Toggling the SplitView using Visual States

Yesterday when I was Toggling the SplitView Pane using a Hamburger Button in a UWP Application, I did it by simply inverting the IsPaneOpen property on the SplitView. This is in conflict with the visual states I had previously declared. An alternative would be for the button to invoke a state change on the AboutViewModel – this relies on knowing what the current state is, as shown in the following code which sits within the AboutViewModel.

public void ToggleSplitView()
    var group = StateManager.StateGroups[typeof (AboutExpandStates)] as StateGroup<AboutExpandStates>;
    var current = group.CurrentState;
    var current = StateManager.CurrentState<AboutExpandStates>();
    StateManager.GoToState(current != AboutExpandStates.Expanded
        ? AboutExpandStates.Expanded
        : AboutExpandStates.Minimised);

Update: There is now a CurrentState method on the StateManager which eliminates the need to explicitly grab a reference to the state group. See bold lines in code above for the change

Leave a comment