Ejemplo n.º 1
0
        private void GotoState(string stateName)
        {
            Control control = VisualStateUtilities.FindNearestStatefulControl(AssociatedObject);

            if (control != null)
            {
                VisualStateManager.GoToState(control, stateName, true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method invokes our VSM state
        /// </summary>
        /// <param name="parameter"></param>
        protected override void Invoke(object parameter)
        {
            if (base.Target != null)
            {
                string stateName = this.StateName;
                if (string.IsNullOrEmpty(stateName) && parameter is string)
                {
                    stateName = parameter.ToString();
                }

                // Locate the nearest state group
                var stateControl = VisualStateUtilities.FindNearestStatefulControl(base.Target);
                if (stateControl != null)
                {
                    VisualStateUtilities.GoToState(stateControl, stateName, UseTransitions);
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateOrientation()
        {
            var control = VisualStateUtilities.FindNearestStatefulControl(this.AssociatedObject as FrameworkElement);

            if (control == null)
            {
                System.Diagnostics.Debugger.Break();
                return;
            }

            if (Window.Current.Bounds.Width <= this.NarrowWidth)
            {
                // narrow
                if (!string.IsNullOrEmpty(this.NarrowStateName))
                {
                    VisualStateManager.GoToState(control, this.NarrowStateName, this.Transitions);
                }
            }
            else
            {
                switch (Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Orientation)
                {
                // landscape
                case Windows.UI.ViewManagement.ApplicationViewOrientation.Landscape:
                    if (!string.IsNullOrEmpty(this.LandscapeStateName))
                    {
                        VisualStateManager.GoToState(control, this.LandscapeStateName, this.Transitions);
                    }
                    break;

                // portrait
                case Windows.UI.ViewManagement.ApplicationViewOrientation.Portrait:
                    if (!string.IsNullOrEmpty(this.PortraitStateName))
                    {
                        VisualStateManager.GoToState(control, this.PortraitStateName, this.Transitions);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        private static void PropertyChangedCallback(DependencyObject dependencyObject,
                                                    DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            var behaviour = (VisualStateBehavior)dependencyObject;

            if (behaviour.IgnoreCallback)
            {
                return;
            }

            if (behaviour.AssociatedObject == null)
            {
                behaviour.AssociatedObject = VisualStateUtilities.FindNearestStatefulControl(behaviour.StatefulElement);
            }

            var element = behaviour.AssociatedObject as Control;

            if (element == null)
            {
                Logger.Warn($"Root control not found for {behaviour.Group} group");
                return;
            }

            var state = dependencyPropertyChangedEventArgs.NewValue as string;

            if (element == null)
            {
                throw new InvalidOperationException("There are not stateful elements");
            }

            if (state == null || !VisualStateManager.GoToState(element, state, false))
            {
                Debug.WriteLine($"Can't go to state: {state}");
            }
            else
            {
                Logger.Info($"State changed to {state}");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes the action.
        /// </summary>
        /// <param name="sender">The <see cref="System.Object"/> that is passed to the action by the behavior. Generally this is <seealso cref="Microsoft.Xaml.Interactivity.IBehavior.AssociatedObject"/> or a target object.</param>
        /// <param name="parameter">The value of this parameter is determined by the caller.</param>
        /// <returns>True if the transition to the specified state succeeds; else false.</returns>
        public object Execute(object sender, object parameter)
        {
            if (string.IsNullOrEmpty(this.StateName))
            {
                return(false);
            }

            if (this.ReadLocalValue(GoToStateAction.TargetObjectProperty) != DependencyProperty.UnsetValue)
            {
                Control control = this.TargetObject as Control;
                if (control == null)
                {
                    return(false);
                }

                return(VisualStateUtilities.GoToState(control, this.StateName, this.UseTransitions));
            }

            FrameworkElement element = sender as FrameworkElement;

            if (element == null || !EventTriggerBehavior.IsElementLoaded(element))
            {
                return(false);
            }

            Control resolvedControl = VisualStateUtilities.FindNearestStatefulControl(element);

            if (resolvedControl == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        CultureInfo.CurrentCulture,
                                                        ResourceHelper.GoToStateActionTargetHasNoStateGroups,
                                                        element.Name));
            }

            return(VisualStateUtilities.GoToState(resolvedControl, this.StateName, this.UseTransitions));
        }