Create your own VisualState in xaml and manually set it to CodeBehind

I have a TabItem style that has VisualStates.

<VisualState x:Name="MouseOver"> 
<!-- Tab turns bronze when mouseover -->
</VisualState>

Now I want to have a custom visual state and manually set the state to codebehind instead of relying on the MouseOver event.

<VisualState x:Name="CustomVisualState">
<!-- this will be a storyboard to cause flashing -->
</VisualState> 

Then I need to install it in CodeBehind.

MyTabItem.VisualState = CustomVisualState.  //something like this
+5
source share
2 answers

Have you tried VisualStateManager.GoToState (Control, "stateName", UseTransition); gets the control, a string with a custom state name and a bool flag for using transitions.

Addtional Example here

+13
source

Try it,

VisualStateManager.GoToElementState(Control, "StateName", true/false);

or

VisualStateManager.GoToState(Control, "StateName", true/false);
+1

All Articles