protected override bool GoToStateCore(Control control, FrameworkElement templateRoot, string stateName, VisualStateGroup group, VisualState state, bool useTransitions)
 {
     if (control == null)
     {
         control = new ContentControl();
     }
     if ((group == null) || (state == null))
     {
         return false;
     }
     if (!GetUseFluidLayout(group))
     {
         return base.GoToStateCore(control, templateRoot, stateName, group, state, useTransitions);
     }
     VisualState currentState = GetCurrentState(group);
     if (currentState == state)
     {
         if (!useTransitions && (LayoutTransitionStoryboard != null))
         {
             StopAnimations();
         }
         return true;
     }
     SetCurrentState(group, state);
     Storyboard layoutStoryboard = ExtractLayoutStoryboard(state);
     List<OriginalLayoutValueRecord> originalLayoutValues = GetOriginalLayoutValues(group);
     if (originalLayoutValues == null)
     {
         originalLayoutValues = new List<OriginalLayoutValueRecord>();
         SetOriginalLayoutValues(group, originalLayoutValues);
     }
     if (!useTransitions)
     {
         if (LayoutTransitionStoryboard != null)
         {
             StopAnimations();
         }
         base.GoToStateCore(control, templateRoot, stateName, group, state, useTransitions);
         SetLayoutStoryboardProperties(control, templateRoot, layoutStoryboard, originalLayoutValues);
         return true;
     }
     if ((layoutStoryboard.Children.Count == 0) && (originalLayoutValues.Count == 0))
     {
         return base.GoToStateCore(control, templateRoot, stateName, group, state, useTransitions);
     }
     templateRoot.UpdateLayout();
     List<FrameworkElement> targets = FindTargetElements(control, templateRoot, layoutStoryboard, originalLayoutValues, MovingElements);
     Dictionary<FrameworkElement, Rect> rectsOfTargets = GetRectsOfTargets(targets, MovingElements);
     Dictionary<FrameworkElement, double> oldOpacities = GetOldOpacities(control, templateRoot, layoutStoryboard, originalLayoutValues, MovingElements);
     if (LayoutTransitionStoryboard != null)
     {
         templateRoot.LayoutUpdated -= ExtendedVisualStateManager.control_LayoutUpdated;
         StopAnimations();
         templateRoot.UpdateLayout();
     }
     base.GoToStateCore(control, templateRoot, stateName, group, state, useTransitions);
     SetLayoutStoryboardProperties(control, templateRoot, layoutStoryboard, originalLayoutValues);
     templateRoot.UpdateLayout();
     Dictionary<FrameworkElement, Rect> newRects = GetRectsOfTargets(targets, null);
     MovingElements = new List<FrameworkElement>();
     foreach (FrameworkElement element in targets)
     {
         if (rectsOfTargets[element] != newRects[element])
         {
             MovingElements.Add(element);
         }
     }
     foreach (FrameworkElement element2 in oldOpacities.Keys)
     {
         if (!MovingElements.Contains(element2))
         {
             MovingElements.Add(element2);
         }
     }
     WrapMovingElementsInCanvases(MovingElements, rectsOfTargets, newRects);
     VisualTransition transition = FindTransition(group, currentState, state);
     templateRoot.LayoutUpdated += ExtendedVisualStateManager.control_LayoutUpdated;
     LayoutTransitionStoryboard = CreateLayoutTransitionStoryboard(transition, MovingElements, oldOpacities);
     LayoutTransitionStoryboard.Completed += (sender, args) =>
     {
         templateRoot.LayoutUpdated -= ExtendedVisualStateManager.control_LayoutUpdated;
         StopAnimations();
     };
     LayoutTransitionStoryboard.Begin();
     return true;
 }