private static void OnVisualStateGroupsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { FrameworkElement element = obj as FrameworkElement; if (element != null) { Control control = VisualStateManager.GetTemplatedParent(element); if (control != null) { System.Diagnostics.Debug.Assert(element == VisualStateManager.GetTemplateRoot(control)); Microsoft.Windows.Controls.VisualStateBehaviorFactory.AttachBehavior(control); } } }