I am writing a custom XAML control with several visual states. I am able to change visual states in the control's code behind, however I am not able to retrieve the current state.
I tried this solution, which looked very good.
Silverlight: VisualStateManager.GetVisualStateGroups doesn't, How can I get them?
However it throws an internal exception, not enough to crash the app, but my IList does not exist. I think the exception occurs because this fails to return anything valid VisualTreeHelper.GetChild(this, 0) as FrameworkElement);
How can I get the visual state of a control from within the code of the control itself.
Xaml code:
<Style TargetType="cc:MyControl" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="cc:MyControl">
<Canvas x:Name="MyControlCanvas" Width="17" Height="43" HorizontalAlignment="Left" VerticalAlignment="Top">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="MyControlStateGroup" >
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Target="rectangle_Copy1.(UIElement.Opacity)" Value="1"/>