【问题标题】:XAML UserControl TriggersXAML 用户控件触发器
【发布时间】:2011-12-01 10:13:47
【问题描述】:

在这个问题上卡了很长时间,不知道我哪里出错了。我收到消息

Triggers collection members must be of type EventTrigger.

我认为我对触发器的了解是正确的,正是这种类型的触发器我不需要事件触发器。

这是我的标记

  <UserControl.Triggers>
     <Trigger SourceName="MainGrid" Property="Grid.IsMouseOver" Value="true">
         <Setter TargetName="DeleteButton" Property="TextBlock.Foreground" Value="#FF222222" />
     </Trigger>
 </UserControl.Triggers>

编辑:

这不是一个修复程序,但我已经以编程方式完成此操作,直到我找到如何在 XAML 中解决此问题。

    private void MainGrid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
    {
        DeleteButton.Foreground = new SolidColorBrush(Color.FromArgb(255, 34, 34, 34));
    }

    private void MainGrid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
    {
        DeleteButton.Foreground = new SolidColorBrush(Color.FromArgb(255, 204, 204, 204));
    }

【问题讨论】:

  • 尝试使用 ...
  • 谢谢,但不幸的是,这也不起作用

标签: c# wpf xaml


【解决方案1】:

将下面的 xaml 放到 UserControl.Triggers 部分:

<EventTrigger SourceName="MainGrid" RoutedEvent="Grid.MouseEnter">
            <BeginStoryboard>
                <Storyboard Storyboard.TargetName="DeleteButton"
                            Storyboard.TargetProperty="Foreground.Color">
                    <ColorAnimationUsingKeyFrames BeginTime="00:00:00">
                        <LinearColorKeyFrame Value="Red"
                                             KeyTime="0:0:0" />
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>            
        </EventTrigger>
        <EventTrigger SourceName="MainGrid"
                      RoutedEvent="Grid.MouseLeave">
            <BeginStoryboard >
                <Storyboard Storyboard.TargetName="DeleteButton"
                            Storyboard.TargetProperty="Foreground.Color">
                    <ColorAnimationUsingKeyFrames BeginTime="00:00:00">
                        <LinearColorKeyFrame Value="Black"
                                             KeyTime="0:0:0" />
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>            
        </EventTrigger>

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 2012-03-21
    • 1970-01-01
    • 2011-08-22
    相关资源
    最近更新 更多