I have a ListView with an ItemContainerStyle defined as such:
<ListView Width="auto"
SelectionMode="Single"
ItemContainerStyle="{StaticResource ItemContStyle}"
....
Then in baseListViewStyle, I have defined some base styles to apply to my ListViews, including a Style trigger:
<Style x:Key="baseListViewStyle" TargetType="ListViewItem">
<Setter Property="Height" Value="20" />
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
The Trigger here highlights the row when mouse is over it. Nice.
I also have a DataTrigger on the ListViewItem:
<Style.Triggers>
<DataTrigger Binding="{Binding IsTestTrue}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource SomeFunkyAnimation}" />
</DataTrigger.EnterActions>
</DataTrigger>
If test is true then a nice little fade animation is played out. This all works except when开发者_运维百科 I move my mouse over the row where "test is true" the animation stops and the mouse over style is displayed.
Any ideas how I can override that style in my DataTrigger?
TIA
Update:
SomeFunkyAnimation animates the background colour. The xaml for it is here:
<Style x:Key="ItemContStyle" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource baseListViewStyle}">
<Style.Resources>
<Storyboard x:Key="SomeFunkyAnimation" FillBehavior="Stop">
<ColorAnimation Storyboard.TargetProperty="Background.Color" RepeatBehavior="Forever" From="Red" To="Pink" Duration="0:0:3"/>
</Storyboard>
</Style.Resources>
The MouseOver trigger is defined in baseListViewStyle. The DataTrigger is defined in ItemContStyle.
I tried removing the MouseOver style trigger but that didn't work as I believe the Listview has a default MouseOver style already defined so it overrides my DataTrigger animation.
Well after dropping a few hours of my life on this problem I finally found a work around. For some reason ColorAnimation just stops animating after a mouse over. Dont know why, maybe a wpf bug who knows. Solution was to rejig my animation. The below does the same thing:
<Storyboard x:Key="SomeFunkyAnimation" FillBehavior="Stop">
<DoubleAnimation Storyboard.TargetProperty="Background.Opacity" RepeatBehavior="Forever" AutoReverse="true" From="0.2" To="1.0" Duration="0:0:1"/>
</Storyboard>
And then same DataTrigger with an additional Setter for the background:
<DataTrigger Binding="{Binding IsTestTrue}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource SomeFunkyAnimation}" />
</DataTrigger.EnterActions>
<Setter Property="Background" Value="Red" />
</DataTrigger>
Peace at last.
加载中,请稍侯......
精彩评论