我的问题很简单:它甚至有可能吗?动画从相互排斥的VisualStateGroups动画相同的属性
假设我想要设置ListBoxItem
的样式,使其默认情况下具有黑色前景,选择时为蓝色,鼠标移过时为红色。我结束了这样的事情:
<!-- assume the default foreground color is black -->
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Duration="0:0:0.2" To="Red" Storyboard.TargetName="contentControl" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Duration="0:0:0.2" To="Blue" Storyboard.TargetName="contentControl" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl x:Name="contentControl" Foreground="{TemplateBinding Foreground}" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
的问题是,ListBoxItem
类已正确放置选择状态在自己的视觉状态组,独立于常见的状态,如鼠标。这意味着ListBoxItem
可以处于选定状态和鼠标悬停状态。
如果选择了ListBoxItem
并正确显示为蓝色,将鼠标移到黑色上会将其恢复为黑色,因为它会转换回正常状态。
有没有什么方法可以帮助我处理这个问题,而无需通过子类化ListBoxItem
并添加我自己的自定义状态?我读过的所有内容都表明这不可能,但对我来说似乎有点可笑。我错过了什么?
+1优先级是什么,我问了 - 不是魔术;) – 2010-09-11 21:08:33