VisualStateManager.GoToState not working?

I’ve had issues with this on and off for a while and thought I should note my solution quickly.

 

Expression Blend will actually use ExtendedVisualStateManager, but the base class VisualStateManager has this solution as well. Basically, due to a bug that was supposed to be fixed, but for whatever reason still exists, the visual state sometimes won’t change using this method. The GoToState method takes a control, a state name string, and Boolean whether to use transition animations.

 

The solution is simple. There is another method called GotoElementState that takes a FrameworkElement, and the rest. Just use this instead and your problems go away.

 

   1: // Avoid this.
   2: VisualStateManager.GoToState(ctrl, stateName, true);
   3:  
   4: // Use this.
   5: VisualStateManager.GoToElementState(ctrl, stateName, true);

Comments

Popular posts from this blog

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

Yet once more into the breech (of altered programming logic)

How to convert SVG data to a Png Image file Using InkScape