已经坚持这一段很长一段时间了,不知道我哪里出错了。我收到了消息
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));
}
答案 0 :(得分: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>
希望这有帮助。