3

Is there a way to prevent the UWP Splitview from closing if a certain condition is met? I have the following PropertyChange Callback implemented:

MySplitView.RegisterPropertyChangedCallback(SplitView.IsPaneOpenProperty, MySplitViewPaneOpenPropertyChanged);

Which looks like this:

private void MySplitViewPaneOpenPropertyChanged(DependencyObject sender, DependencyProperty dp)
    {
        if (preventClose == true)
        {
            TrashSplitView.IsPaneOpen = true;
        }
    }

This code keeps the splitview pane open, but starts the animation briefly. Is there a way to prevent the animation from ever starting?

Allen Rufolo
  • 1,173
  • 1
  • 11
  • 14

1 Answers1

5

After some more digging into the Methods and Events that the Splitview has to offer, I found a simple solution. Hopefully this answer will help someone else trying to do the same.

There is an Event on the Splitview class called "PaneClosing"

<Splitview PaneClosing="SplitView_PaneClosing"/>

In the event handler, you can cancel this closing animation completely like this:

private void SplitView_PaneClosing(SplitView sender, SplitViewPaneClosingEventArgs args)
{
    if (preventClose == true)
    {
        args.Cancel = true;
    }
}
Allen Rufolo
  • 1,173
  • 1
  • 11
  • 14
  • 1
    Haha, i just found this solution and when i came back here you already solved it yourself. – Thomas Schneiter Nov 30 '16 at 14:01
  • After much experimentation I determined cancellation via SplitViewPaneClosingEventArgs only works when the the DisplayMode is Overlay or CompactOverlay, and the pane is closed via the user interacting with the light dismiss layer, but not when it's closed programmatically (i.e. using IsPaneOpen = false) – Will Mar 13 '20 at 18:48
  • For me that made the whole UI around the spiltview pane not responsible for any user input. – AtosNicoS Mar 24 '22 at 10:24