ContentControl can't have VisualStateManager?

Jun 20, 2009 at 8:24 PM

I'm using VSM in ContentControl instead of UserControl.  VSM returns False if I call like that ~ 

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

When I check GetTemplateRoot from VSM, I found that you guys are casting the control (argument) to UserControl. So, I will get null since I'm using ContentControl. And also, VisualTreeHelper.GetChildrenCount(control) will always return 0 since myview hasn't been rendered yet. 

private static FrameworkElement GetTemplateRoot(Control control)

        {

            UserControl userControl = control as UserControl;

            if (userControl != null)

            {

                // If using a UserControl, the states will be specified on the

                // root of the content instead of the root of the template.

                return userControl.Content as FrameworkElement;

            }

            else

            {

                if (VisualTreeHelper.GetChildrenCount(control) > 0)

                {

                    return VisualTreeHelper.GetChild(control, 0) as FrameworkElement;

                }

            }

 

            return null;

        }

Note: Please answer my old question as well http://wpf.codeplex.com/Thread/View.aspx?ThreadId=59926 Thanks.

Coordinator
Jun 23, 2009 at 4:12 AM

VSM in the toolkit will only work with controltemplates and UserControl.Content.  VSM in dev10 will support your scenario.