I am trying to add a swipe gesture to the SplitView control (aka "hamburger menu") of UWP, similar to the swipe left/right of a Pivot control. How can I set a gesture to change the Display mode of it?
In iOS 8 and later, I can use UISplitViewController and set presentsWithGesture property to do that but there is not a similar thing in WinRT.
Now after reading this blog: http://blogs.msdn.com/b/cdndevs/archive/2015/07/10/uwp-new-controls-part-2-splitview.aspx, I realized that there is the DisplayMode property in SplitView control and I should use VisualStateManager to change the state of it But how can I use vsm to pan the left Pane in and out? I am not aware that this is achievable with vsm.
Any help/hint would be greatly appreciated.
Well, vsm is used in making Responsive UI in that blog. To add a swipe gesture in SplitView, here's what I did:
Interesting question! :)
I recently created a
SwipeableSplitView
which extends theSplitView
control to enable a swipe from left edge gesture when theDisplayMode
is set toOverlay
(as I don't see the point to have it in other modes, but feel free to extend it whenever needed).All I am doing is, inside the control's style, create another layer on top of the
PaneRoot
layer and handle all the gestures there.While updating the
TranslateX
of the new layer's transform object, I am also updating thePaneRoot
's to keep their position in sync.Keep in mind that because the
IsPaneOpen
property is not virtual, I have to create another oneIsSwipeablePaneOpen
to wrap the former around. So whenever you feel like using theIsPaneOpen
property, useIsSwipeablePaneOpen
instead.This is how it works in a demo app I created in GitHub. You can find the full source code here.
Credits