我想知道是否有可能将视觉状态(在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的嵌套文本块不会相应地更改其颜色。我能以这种方式应用视觉状态吗?
谢谢,丹尼洛。
发布于 2011-07-01 12:39:50
修复问题:可视化状态是在控件模板之外定义的,因此我必须使用VisualStateManager.GoToElementState而不是GoToState。
发布于 2011-06-29 02:50:02
可以,VisualStateManager可以更改任何控件的状态。你的代码肯定还有其他问题。
https://stackoverflow.com/questions/6510880
复制相似问题