コード例 #1
0
        protected void RaiseCurrentStateChanged(VisualStateGroup stateGroup, VisualState oldState, VisualState newState, Control control)
        {
            if (stateGroup == null)
            {
                throw new ArgumentNullException("stateGroup");
            }

            if (newState == null)
            {
                throw new ArgumentNullException("newState");
            }

            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            FrameworkElement root = VisualStateManager.GetTemplateRoot(control);

            if (root == null)
            {
                return; // Ignore if a ControlTemplate hasn't been applied
            }

            stateGroup.RaiseCurrentStateChanged(root, oldState, newState, control);
        }
コード例 #2
0
ファイル: VisualStateManager.cs プロジェクト: ynkbt/moon
        /// <summary>
        ///     Transitions a control's state.
        /// </summary>
        /// <param name="control">The control who's state is changing.</param>
        /// <param name="stateName">The new state that the control is in.</param>
        /// <param name="useTransitions">Whether to use transition animations.</param>
        /// <returns>true if the state changed successfully, false otherwise.</returns>
        public static bool GoToState(Control control, string stateName, bool useTransitions)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            if (stateName == null)
            {
                throw new ArgumentNullException("stateName");
            }

            FrameworkElement root = VisualStateManager.GetTemplateRoot(control);

            if (root == null)
            {
                return(false); // Ignore state changes if a ControlTemplate hasn't been applied
            }

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

            if (groups == null)
            {
                return(false);
            }

            // System.Diagnostics.Debug.WriteLine("Going to " + stateName);
            VisualState      state;
            VisualStateGroup group;

            if (!VisualStateManager.TryGetState(groups, stateName, out group, out state))
            {
                return(false);
            }

            // Look for a custom VSM, and call it if it was found, regardless of whether the state was found or not.
            // This is because we don't know what the custom VSM will want to do. But for our default implementation,
            // we know that if we haven't found the state, we don't actually want to do anything.
            VisualStateManager customVsm = GetCustomVisualStateManager(root);

            if (customVsm != null)
            {
                return(customVsm.GoToStateCore(control, root, stateName, group, state, useTransitions));
            }
            else if (state != null)
            {
                return(GoToStateInternal(control, root, group, state, useTransitions));
            }

            return(false);
        }
コード例 #3
0
        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);
                }
            }
        }