Reputation: 67
Im now designing a UWP and I want to add a swipe gesture to open my Hamburger Menu. However, in one of my pages I add in a pivot, and then the swipe gesture doesn't open the Menu, instead it switches the PivotItem.
How to make them both alive in the same page?
here is my code about swipe gesture: (thx to http://blog.csdn.net/github_36704374/article/details/59580697)
namespace Humberger
{
public sealed partial class MainPage : Page
{
private double x = 0; //用来接收手势水平滑动的长度
public MainPage()
{
this.InitializeComponent();
this.ManipulationMode = ManipulationModes.TranslateX; //设置这个页面的手势模式为横向滑动
this.ManipulationCompleted += The_ManipulationCompleted; //订阅手势滑动结束后的事件
this.ManipulationDelta += The_ManipulationDelta; //订阅手势滑动事件
}
//手势滑动中
private void The_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
x += e.Delta.Translation.X; //将滑动的值赋给x
}
//手势滑动结束
private void The_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
if (x > 100) //判断滑动的距离
MySplit.IsPaneOpen = true; //打开汉堡菜单
if (x < -100)
MySplit.IsPaneOpen = false; //关闭汉堡菜单
x = 0; //清零x,不然x会累加
}
//汉堡菜单点击事件
private void Humberger_Click(object sender, RoutedEventArgs e)
{
MySplit.IsPaneOpen = !MySplit.IsPaneOpen;
}
}
}
Upvotes: 2
Views: 113
Reputation: 39006
Yes, Pivot
or Hub
control will swallow all your horizontal user inputs. But if you just want to be able to swipe from the edge to bring out the drawer of your menu, here's a trick -
Give your
Pivot
a left margin of1px
.
Doing so will allow the host element to receive touch manipulations when swiping from the edge of the device.
I did the exact thing a couple of years ago in this video, with a Pivot
and a RadSideDrawer
from Telerik. This RadSideDrawer
control is now open sourced as part of the Telerik UI for UWP.
I also rolled my own SwipeableSplitView
control which is explained here.
Hope this helps!
Upvotes: 4