Reputation: 700
Been stuck on this one for quite a while, not sure where I'm going wrong. I get the message
Triggers collection members must be of type EventTrigger.
I think my knowledge of triggers is correct and it is this type of trigger I need not an event trigger.
This is my mark-up
<UserControl.Triggers>
<Trigger SourceName="MainGrid" Property="Grid.IsMouseOver" Value="true">
<Setter TargetName="DeleteButton" Property="TextBlock.Foreground" Value="#FF222222" />
</Trigger>
</UserControl.Triggers>
Edit:
It's not a fix but I have done this programmatically until I find how to solve this problem in 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));
}
Upvotes: 1
Views: 4803
Reputation: 8930
Place the xaml below to the UserControl.Triggers
section:
<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>
Hope this helps.
Upvotes: 1