ApplyTemplate() public method

public ApplyTemplate ( ) : bool
return bool
        /// <summary>
        /// Transitions the control between two states.
        /// </summary>
        /// <param name="control">The <see cref="Windows.UI.Xaml.Controls.Control"/> to transition between states.</param>
        /// <param name="stateName">The state to transition to.</param>
        /// <param name="useTransitions">True to use a <see cref="Windows.UI.Xaml.VisualTransition"/> to transition between states; otherwise, false.</param>
        /// <returns>True if the <paramref name="control"/> is successfully transitioned to the new state; otherwise, false.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="control"/> or <paramref name="stateName"/> is null.</exception>
        public static bool GoToState(Control control, string stateName, bool useTransitions)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            if (string.IsNullOrEmpty(stateName))
            {
                throw new ArgumentNullException("stateName");
            }

            control.ApplyTemplate();
            return VisualStateManager.GoToState(control, stateName, useTransitions);
        }
Example #2
0
		VisualStateCache PseudoDisable(Control control)
		{
			if (VisualTreeHelper.GetChildrenCount(control) == 0)
				control.ApplyTemplate();

			VisualStateManager.GoToState(control, "Disabled", true);

			var rootElement = (FrameworkElement)VisualTreeHelper.GetChild(control, 0);

			var cache = new VisualStateCache();
			IList<VisualStateGroup> groups = VisualStateManager.GetVisualStateGroups(rootElement);

			VisualStateGroup common = null;
			foreach (var group in groups)
			{
				if (group.Name == "CommonStates")
					common = group;
				else if (group.Name == "FocusStates")
					cache.FocusStates = group;
				else if (cache.FocusStates != null && common != null)
					break;
			}

			if (cache.FocusStates != null)
				groups.Remove(cache.FocusStates);

			if (common != null)
			{
				foreach (VisualState state in common.States)
				{
					if (state.Name == "Normal")
						cache.Normal = state;
					else if (state.Name == "Pressed")
						cache.Pressed = state;
					else if (state.Name == "PointerOver")
						cache.PointerOver = state;
				}

				if (cache.Normal != null)
					common.States.Remove(cache.Normal);
				if (cache.Pressed != null)
					common.States.Remove(cache.Pressed);
				if (cache.PointerOver != null)
					common.States.Remove(cache.PointerOver);
			}

			return cache;
		}