我想知道是否可以将视觉状态(在 WPF 4 中)应用于嵌套控件。我有一个堆栈面板,其中包含一些我想根据变化状态更改的元素。
<StackPanel x:Name="panPremioRaggiunto">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="StatiComuni">
<VisualState Name="PremioNonRaggiunto" />
<VisualState Name="PremioRaggiunto">
<Storyboard>
<ColorAnimation Storyboard.TargetName="lblPremioRaggiunto" Storyboard.TargetProperty="Foreground" To="Green" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBlock x:Name="lblPremioRaggiunto">TEXT</TextBlock>
</StackPanel>
当我尝试使用此代码更改整个堆栈面板的状态时
VisualStateManager.GoToState(panPremioRaggiunto, "PremioRaggiunto", False)
什么也没有发生:名为 lblPremioRaggiunto 的嵌套文本块不会改变他的颜色。我可以以这种方式应用视觉状态吗?
谢谢,达尼洛。