Why VSM is looking for ROOT?

Jun 20, 2009 at 8:35 PM

I'm wondering how come VSM is looking for root object instead of reading VSG directly? 

Let's say I have UserControl as below. 

<UserControl .....
.....
<VisualStateManager.VisualStateGroups>
</VisualStateManager.VisualStateGroups> 

....

<Grid> 
....
</Grid>
</UserControl>

I changed the state from code as below. then, it won't work. 

bool result = VisualStateManager.GoToState(this, "Loaded", false);

Code should be changed like that .

IList<VisualStateGroup> groups = VisualStateManager.GetVisualStateGroupsInternal(control);

 

 

Coordinator
Jun 23, 2009 at 4:11 AM

This version of VSM is only meant to work in control templates and UserControl.Content.  Dev10 will have a version where it will work for any FrameworkElement.  In addition, the code to look for the VSGs is more robust. 

By the way, your solution didn't suggest how the reference to control was found.  This will be different depending if its coming from the template or directly from the control.