【发布时间】:2014-10-30 21:17:23
【问题描述】:
控件的内容是否可以对其父级的视觉状态变化做出反应?
在以下示例中,当父控件处于活动状态时,我希望文本块的前景变为红色。但是这段代码不起作用:
<local:ExpandKeyButton x:Name="xpand" Height="30">
<TextBlock x:Name="tb">
Test
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="General">
<VisualState x:Name="Idle" />
<VisualState x:Name="Active">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="tb" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</TextBlock>
</local:ExpandKeyButton>
【问题讨论】:
-
storyboard可以向内定位——也就是说,如果你在local:ExpandKeyButton上设置了VisualStateGroups,它仍然可以修改TextBlock
-
@bdimag 第一部分是真的,但第二部分不是,因为
VisualStateGroups在那里无效。 VisualStateGroups 只能在 ControlTemplate 或 UserControl 的根元素下定义。
标签: c# wpf xaml windows-phone windows-phone-8.1