开发者

Add Visual State to nested controls with WPF 4

I'd like to know if is it possible to apply a Visual State (in WPF 4) to nested controls. I've got a stack panel that contains some elements I'd like to change according to variation state.

<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&g开发者_开发百科t;
 <TextBlock x:Name="lblPremioRaggiunto">TEXT</TextBlock>
</StackPanel>

When I try to change the state of entire stack panel with this code

VisualStateManager.GoToState(panPremioRaggiunto, "PremioRaggiunto", False)

nothing happens: nested textblock named lblPremioRaggiunto don't change his color according. Can I apply a visual state in this manner?

Thanks, Danilo.


Yes, VisualStateManager can change the state of any control. You must have some other issue with your code.


Fixed issue: visual states are defined outside a control template so I have to use VisualStateManager.GoToElementState instead of GoToState.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜