我现在正在设计一个 UWP,我想添加一个滑动手势来打开我的汉堡菜单。但是,在我的一个页面中,我添加了一个数据透视表,然后滑动手势不会打开菜单,而是切换数据透视表项。
如何让它们都活在同一个页面中?
这是我关于滑动手势的代码: (感谢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;
}
}
}
最佳答案
是的,Pivot
或 Hub
控件将吞掉所有水平用户输入。但如果您只是想从边缘滑动以调出菜单抽屉,这里有一个技巧 -
Give your
Pivot
a left margin of1px
.
这样做将允许主机元素在从设备边缘滑动时接收触摸操作。
几年前我在这个 video 中做了同样的事情,带有 Telerik 的 Pivot
和 RadSideDrawer
。此 RadSideDrawer
控件现已作为 Telerik UI for UWP 的一部分开源。 .
我还推出了自己的 SwipeableSplitView
控件,对此进行了解释 here .
希望这有帮助!
关于c# - 当 UWP 中有枢轴时,滑动手势不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45778977/