private void Evaluate() { if (TargetObject != null) { VisualStateUtilities.GoToState(stateName: (!ComparisonLogic.EvaluateImpl(Binding, ComparisonConditionType.Equal, Value)) ? FalseState : TrueState, element: TargetObject, useTransitions: true); } }
void Responsive() { if (this.ActualWidth > 700) { VisualStateUtilities.GoToState(this, "FullWindows", false); } else if (this.ActualWidth > 500) { VisualStateUtilities.GoToState(this, "Narrow", false); } else if (this.ActualWidth > 200) { VisualStateUtilities.GoToState(this, "ExtraNarrow", false); } else { VisualStateUtilities.GoToState(this, "Minimum", false); } if (Window.Current.Bounds.Height < 700) { RootGrid.Height = 60; } else { RootGrid.Height = 75; } }
internal void InvokeImpl(FrameworkElement stateTarget) { if (stateTarget != null) { VisualStateUtilities.GoToState(stateTarget, this.StateName, this.UseTransitions); } }
private void MouseUp(object sender, MouseButtonEventArgs e) { if (!(Parent as MenuItem).IsSubmenuOpen) { VisualStateUtilities.GoToState(Parent, MouseUpState, true); } }
public void Attach(DependencyObject associatedObject) { StatefulElement = (FrameworkElement)associatedObject; var visualGroup = VisualStateUtilities.GetVisualStateGroups(StatefulElement).First(group => group.Name == Group); visualGroup.CurrentStateChanged += OnVisualStateChanged; }
public void Detach() { var visualGroup = VisualStateUtilities.GetVisualStateGroups(StatefulElement).First(group => group.Name == Group); visualGroup.CurrentStateChanged -= OnVisualStateChanged; AssociatedObject = null; }
internal void InvokeImpl(FrameworkElement stateTarget) { if (stateTarget == null) { return; } VisualStateUtilities.GoToState(stateTarget, StateName, UseTransitions); }
public void GoToState_OnCustomControlTemplate_WorksProperly() { string testStateName = "Test"; Button statefulButton = CreateButtonWithCustomState(testStateName); bool success = VisualStateUtilities.GoToState(statefulButton, testStateName, true); Assert.IsTrue(success, "GoToState on a valid state in a ControlTemplate should navigate to the state correctly."); }
protected override void Invoke(object parameter) { if (_stateTarget == null || StateName == null) { return; } VisualStateUtilities.GoToState(_stateTarget, StateName, UseTransitions); }
private void GotoState(string stateName) { Control control = VisualStateUtilities.FindNearestStatefulControl(AssociatedObject); if (control != null) { VisualStateManager.GoToState(control, stateName, true); } }
private void OnLoaded(object sender, RoutedEventArgs e) { AssociatedObject.MouseDown += MouseDown; AssociatedObject.MouseUp += MouseUp; AssociatedObject.MouseEnter += MouseEnter; AssociatedObject.MouseLeave += MouseLeave; VisualStateUtilities.TryFindNearestStatefulControl(AssociatedObject, out Parent); }
public void FindNearestStatefulControl_ControlTemplateChild_FindsAppropriateParent() { Button templatedButton = CreateButtonWithCustomTemplate(); FrameworkElement child = VisualTreeHelper.GetChild(templatedButton, 0) as FrameworkElement; FrameworkElement nearestControl; VisualStateUtilities.TryFindNearestStatefulControl(child, out nearestControl); Assert.AreEqual(nearestControl, templatedButton, "Using child Grid of Button's ControlTemplate as context, closest stateful control should be Button."); }
void Responsive() { if (Window.Current.Bounds.Width < 640) { VisualStateUtilities.GoToState(this, "Narrow", false); } else { VisualStateUtilities.GoToState(this, "Wide", false); } }
void Responsive(double width) { if (width <= 700) { VisualStateUtilities.GoToState(this, "Minimal", false); } else { VisualStateUtilities.GoToState(this, "Normal", false); } }
void Responsive(double width) { if (width <= 600) { VisualStateUtilities.GoToState(this, "Narrow", false); } else { VisualStateUtilities.GoToState(this, "Wide", false); } }
public void GetVisualStateGroups_UserControlControlWithChildStates_ReturnsChildStates() { Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>(); UserControl userControl = CreateUserControlWithContent(stateGrid); using (new StubWindow(userControl)) { IList vsgs = VisualStateUtilities.GetVisualStateGroups(userControl); Assert.AreEqual(vsgs.Count, 1, "Should find 1 VisualStateGroup on the UserControl"); } }
void Responsive() { if (Window.Current.Bounds.Width < 1000) { VisualStateUtilities.GoToState(this, nameof(HalfSnap), false); } else { VisualStateUtilities.GoToState(this, nameof(Normal), false); } }
public void GoToState_OnUserControl_WorksProperly() { Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>(); UserControl userControl = CreateUserControlWithContent(stateGrid); userControl.Content = stateGrid; bool success = VisualStateUtilities.GoToState(userControl, VisualStateHelper.ArbitraryThirdStateName, true); Assert.IsTrue(success, "GoToState on a valid UserControl state should navigate to the state correctly."); }
private void HookUptoCompletedEvent(FrameworkElement stateTarget, string stateName) { if (VisualStateChangedCommand != null) { _visualStateGroupOfTheStateName = VisualStateUtilities.GetVisualStateGroups(stateTarget) .OfType <VisualStateGroup>() .FirstOrDefault(vsg => vsg.States.OfType <VisualState>().Any(vs => vs.Name == stateName)); if (_visualStateGroupOfTheStateName != null) { _visualStateGroupOfTheStateName.CurrentStateChanged += OnVisualStateGroupCurrentStateChanged; } } }
public void FindNearestStatefulControl_ContextNestedSeveralLevelsDeep_FindsAppropriateParent() { Button button = CreateButton(); Grid grid = VisualStateHelper.CreateObjectWithStates <Grid>(); UserControl userControl = CreateUserControlWithContent(grid); grid.Children.Add(button); FrameworkElement nearestControl; VisualStateUtilities.TryFindNearestStatefulControl(button, out nearestControl); Assert.AreEqual(nearestControl, userControl, "Using child Grid of UserControl as context, closest stateful control should be UserControl."); }
public void UpdateVisualState(string visualState) { if (AssociatedObject != null) { FrameworkElement stateTarget; if (VisualStateUtilities.TryFindNearestStatefulControl(AssociatedObject, out stateTarget)) { bool useTransitions = _initialized; VisualStateUtilities.GoToState(stateTarget, visualState, useTransitions); _initialized = true; } } }
protected override void Invoke(object parameter) { if (this.AssociatedObject != null && _stateTarget != null) { var state = !string.IsNullOrWhiteSpace(this.StateName) ? this.StateName : parameter != null?parameter.ToString() : ""; if (!string.IsNullOrEmpty(state)) { VisualStateUtilities.GoToState(_stateTarget, state, this.UseTransitions); } } }
private void SetVisualState() { if (AssociatedObject == null || DataEnum == null) { return; } var stateName = String.IsNullOrEmpty(FinalStateNameFormat) ? DataEnum.ToString() : String.Format(FinalStateNameFormat, DataEnum.ToString()); if (StateTarget == null) { return; } HookUptoCompletedEvent(StateTarget, stateName); VisualStateUtilities.GoToState(StateTarget, stateName, UseTransitions); }
void Responsive() { if (Window.Current.Bounds.Width < 770) { VisualStateUtilities.GoToState(this, "Snap", false); } else if (Window.Current.Bounds.Width < 1000) { VisualStateUtilities.GoToState(this, "HalfSnap", false); } else { VisualStateUtilities.GoToState(this, "Normal", false); } }
private void UpdateVisualState( string visualState, bool useTransitions) { if (AssociatedObject != null) { FrameworkElement stateTarget; if (VisualStateUtilities.TryFindNearestStatefulControl( AssociatedObject, out stateTarget)) { VisualStateUtilities.GoToState( stateTarget, visualState, useTransitions); } } }
/// <summary> /// Called when the target changes. If the TargetName property isn't set, this action has custom behavior. /// </summary> /// <param name="oldTarget"></param> /// <param name="newTarget"></param> /// <exception cref="InvalidOperationException">Could not locate an appropriate FrameworkElement with states.</exception> protected override void OnTargetChanged(FrameworkElement oldTarget, FrameworkElement newTarget) { base.OnTargetChanged(oldTarget, newTarget); FrameworkElement frameworkElement = null; if (string.IsNullOrEmpty(this.TargetName) && !this.IsTargetObjectSet) { VisualStateUtilities.TryFindNearestStatefulControl(this.AssociatedObject as FrameworkElement, out frameworkElement); } else { frameworkElement = this.Target; } this.StateTarget = frameworkElement; }
void Responsive(double width) { if (width <= 500) { VisualStateUtilities.GoToState(this, "Minimal", false); } #if WINDOWS_PHONE_APP else if (width < 500) #else else if (width < 870) #endif { VisualStateUtilities.GoToState(this, "Medium", false); } else { VisualStateUtilities.GoToState(this, "Normal", false); } }
protected override void OnTargetChanged(FrameworkElement oldTarget, FrameworkElement newTarget) { base.OnTargetChanged(oldTarget, newTarget); FrameworkElement target; if (string.IsNullOrEmpty(TargetName) && !IsTargetObjectSet) { VisualStateUtilities.TryFindNearestStatefulControl(AssociatedObject as FrameworkElement, out target); } else { target = Target; } _stateTarget = target; }
private void Evaluate() { if (this.TargetObject != null) { string stateName = null; if (ComparisonLogic.EvaluateImpl(this.Binding, ComparisonConditionType.Equal, this.Value)) { stateName = this.TrueState; } else { stateName = this.FalseState; } VisualStateUtilities.GoToState(this.TargetObject, stateName, true); } }
/// <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); } } }