2017-08-20 19 views
2

現在我正在設計UWP並且想要添加滑動手勢來打開我的漢堡菜單。但是,在我的一個頁面中添加了一個數據透視表,然後滑動手勢不會打開菜單,而是切換PivotItem。在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; 
    } 
} 

}

+2

是的,'Pivot'會吞下你所有的水平用戶輸入。訣竅是給它一個'1'的左邊距。這將允許您從父頁面的左邊緣滑動。 –

回答

4

是,PivotHub控制會吞下所有水平用戶輸入。但如果你只是希望能夠從邊緣輕掃,帶出你的菜單的抽屜裏,這裏有一個竅門 -

給你一個Pivot保證金1px

這樣做將允許主機元素在從設備邊緣滑動時接收觸摸操作。

幾年前,我在這個video上做了一件確切的事情,Telerik的PivotRadSideDrawer。此RadSideDrawer控件現已作爲Telerik UI for UWP的一部分開源。

我也推出了我自己的SwipeableSplitView控件,這個控件是here

希望這會有所幫助!