/// <summary>
        /// Change to the correct visual state for the textbox.
        /// </summary>
        /// <param name="useTransitions">
        /// true to use transitions when updating the visual state, false to
        /// snap directly to the new visual state.
        /// </param>
        internal void ChangeVisualState(bool useTransitions)
        {
            // Update the CommonStates group
            if (!IsEnabled)
            {
                VisualStateHelper.GoToState(this, useTransitions, VisualStateHelper.StateDisabled, VisualStateHelper.StateNormal);
            }
            else if (isHovered)
            {
                VisualStateHelper.GoToState(this, useTransitions, VisualStateHelper.StateMouseOver, VisualStateHelper.StateNormal);
            }
            else
            {
                VisualStateHelper.GoToState(this, useTransitions, VisualStateHelper.StateNormal);
            }

            // Update the FocusStates group
            if (hasFocus && IsEnabled)
            {
                VisualStateHelper.GoToState(this, useTransitions, VisualStateHelper.StateFocused, VisualStateHelper.StateUnfocused);
            }
            else
            {
                VisualStateHelper.GoToState(this, useTransitions, VisualStateHelper.StateUnfocused);
            }

            // Update the WatermarkStates group
            if (!hasFocus && this.WatermarkText != null && string.IsNullOrEmpty(this.Text))
            {
                VisualStateHelper.GoToState(this, useTransitions, VisualStateHelper.StateWatermarked, VisualStateHelper.StateUnwatermarked);
            }
            else
            {
                VisualStateHelper.GoToState(this, useTransitions, VisualStateHelper.StateUnwatermarked);
            }
        }
        public override void Execute(object parameter)
        {
            if (tabControlAsControl == null)
            {
                tabControlAsControl = MapApplication.Current.FindObjectInLayout(_tabControlName) as Control;
            }

            //
            // Case one - the content control is hosted within a Tab Control (OOTB layouts)
            //
            if (tabControlAsControl is TabControl)
            {
                TabItem    tab        = null;
                TabControl tabControl = tabControlAsControl as TabControl;
                if (tabIndex == -1)
                {
                    for (int i = 0; i < tabControl.Items.Count; i++)
                    {
                        tab = tabControl.Items[i] as TabItem;
                        if (tab.Name == _tabName)
                        {
                            tabIndex = i;
                            break;
                        }
                    }
                }

                if (tabIndex == -1)
                {
                    throw new Exception(string.Format(
                                            ESRI.ArcGIS.Mapping.Controls.Resources.Strings.NotFoundInLayout, _tabName));
                }
                tab = tabControl.Items[tabIndex] as TabItem;
                Storyboard visualStateStoryboard = null;
                Storyboard resourceStoryboard    = null;

                bool show         = false;
                bool useGoToState = false;
                if (tabControl.SelectedIndex != tabIndex || tabControlAsControl.Visibility == Visibility.Collapsed)
                {
                    if (VisualStateManagerHelper.StateWellDefined(tabControl, ControlNames.VISUAL_STATE_SHOW_CONTENTCONTROL, true))
                    {
                        useGoToState = true;
                    }
                    else
                    {
                        visualStateStoryboard = VisualStateManagerHelper.FindStoryboard(tabControl, null, ControlNames.VISUAL_STATE_SHOW_CONTENTCONTROL, true);
                    }
                    resourceStoryboard = findStoryboardIncludedInResources(ControlNames.VISUAL_STATE_SHOW_CONTENTCONTROL);
                    show = true;
                }
                else
                {
                    if (VisualStateManagerHelper.StateWellDefined(tabControl, ControlNames.VISUAL_STATE_HIDE_CONTENTCONTROL, true))
                    {
                        useGoToState = true;
                    }
                    else
                    {
                        visualStateStoryboard = VisualStateManagerHelper.FindStoryboard(tabControl, null, ControlNames.VISUAL_STATE_HIDE_CONTENTCONTROL, true);
                    }
                    resourceStoryboard = findStoryboardIncludedInResources(ControlNames.VISUAL_STATE_HIDE_CONTENTCONTROL);
                }

                //
                // Hosted in tab: Case one - storyboard for showing/hiding the tab control has been specified
                //
                if (visualStateStoryboard != null || resourceStoryboard != null || useGoToState)
                {
                    if (show)
                    {
                        tabControl.SelectedIndex = tabIndex;
                        tab.Visibility           = Visibility.Visible;
                    }

                    //for (int i = storyBoard.Children.Count - 1; i >= 0; i--)//set the target properties if missing
                    //{
                    //    var timeLine = storyBoard.Children[i];
                    //    var timeLineTargetXName = Storyboard.GetTargetName(timeLine);
                    //    if (string.IsNullOrEmpty(timeLineTargetXName))
                    //    {
                    //        Storyboard.SetTarget(timeLine, tabControl);
                    //    }
                    //}
                    //if (_currentlyExecutingAnimation != null)
                    //    _currentlyExecutingAnimation.Stop();
                    //_currentlyExecutingAnimation = visualStateStoryboard;

                    if (useGoToState)
                    {
                        string showHideString = show ? ControlNames.VISUAL_STATE_SHOW_CONTENTCONTROL :
                                                ControlNames.VISUAL_STATE_HIDE_CONTENTCONTROL;
                        string state = string.Format("{0}_{1}", tabControl.Name, showHideString);
                        VisualStateHelper.GoToState(tabControl, true, state);
                    }

                    if (visualStateStoryboard != null)
                    {
                        visualStateStoryboard.Begin(); //if animation was defined
                    }
                    if (resourceStoryboard != null)
                    {
                        resourceStoryboard.Begin();
                    }
                }
                //
                // Hosted in tab: Case two - No animation for showing/hiding the tab control was specified, so simply show/hide via visibility
                //
                else
                {
                    if (show)
                    {
                        tabControl.SelectedIndex       = tabIndex;
                        tab.Visibility                 = Visibility.Visible;
                        tabControlAsControl.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        tabControlAsControl.Visibility = Visibility.Collapsed;
                    }
                }
            }
            //
            // Case two - the content control is hosted an accordion
            //
            else if (tabControlAsControl is Accordion)
            {
                AccordionItem tab       = null;
                Accordion     accordion = tabControlAsControl as Accordion;
                int           index     = -1;
                for (int i = 0; i < accordion.Items.Count; i++)
                {
                    tab = accordion.Items[i] as AccordionItem;
                    if (tab.Name == _tabName)
                    {
                        index = i;
                        break;
                    }
                }
                if (index == -1)
                {
                    throw new Exception(string.Format(
                                            ESRI.ArcGIS.Mapping.Controls.Resources.Strings.NotFoundInLayout, _tabName));
                }
                bool show = (accordion.SelectedIndex != index || accordion.Visibility == Visibility.Collapsed);
                accordion.SelectedIndex = index;
                if (show)
                {
                    AccordionItem accItem = accordion.Items[index] as AccordionItem;
                    accItem.Visibility             = Visibility.Visible;
                    tabControlAsControl.Visibility = Visibility.Visible;
                }
                else
                {
                    tabControlAsControl.Visibility = Visibility.Collapsed;
                }
            }
        }