如何同时使用Trigger
IsSelected
和VisualState
MouseOver
?如果没有选择元素并且它被悬停,我不会应用样式。
触发器很容易:
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
...
</Trigger>
</ControlTemplate.Triggers>
以及VisualStates一样:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="MouseOver">
<Storyboard>
...
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
但我如何结合这些?
答案 0 :(得分:0)
您可以在新VisualState x:Name="Selected"
中定义VisualStateGroup x:Name="SelectedStates"
。然后,因为每次控件只有一个状态,所以MouseOver和Selected是相互独立的。请参阅Mitesh Sureja's Blog。
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="MouseOver">
<Storyboard>
...
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectedStates">
<VisualState x:Name="Selected">
<Storyboard>
...
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
或者你可以像克莱门斯所说的那样做。见Visual State Manager vs. Triggers in WPF。
修改强>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter ... />
</MultiTrigger>
</Style.Triggers>