Example #1
0
        public static bool GoToState(/*VisualElement*/ BaseHandle visualElement, string name)
        {
            if (!visualElement.IsSet(VisualStateGroupsProperty))
            {
                return(false);
            }

            var groups = (IList <VisualStateGroup>)visualElement.GetValue(VisualStateGroupsProperty);

            foreach (VisualStateGroup group in groups)
            {
                if (group.CurrentState?.Name == name)
                {
                    // We're already in the target state; nothing else to do
                    return(true);
                }

                // See if this group contains the new state
                var target = group.GetState(name);
                if (target == null)
                {
                    continue;
                }

                // If we've got a new state to transition to, unapply the setters from the current state
                if (group.CurrentState != null)
                {
                    foreach (Setter setter in group.CurrentState.Setters)
                    {
                        setter.UnApply(visualElement);
                    }
                }

                // Update the current state
                group.CurrentState = target;

                // Apply the setters from the new state
                foreach (Setter setter in target.Setters)
                {
                    setter.Apply(visualElement);
                }

                return(true);
            }

            return(false);
        }
Example #2
0
 public static bool HasVisualStateGroups(this /*VisualElement*/ BaseHandle element)
 {
     return(element.IsSet(VisualStateGroupsProperty));
 }