Disabling swipe gesture in Windows Phone 8.1 pivot control

孤街醉人 提交于 2020-01-02 23:04:40

问题


I am making a Universal app. For the windows phone part I have implemented a pivot page in it. Now I want the swipe gesture (for navigating through different pivot items) in pivot page to be disabled so that only when a button on the first PivotItem is tapped then it shows the second PivotItem. I tried setting the IsHitTestVisible property of the Pivot control to false but then all the PivotItem are blocked.


回答1:


It goes against the WINDOWS UI Guide and shouldn't really be implemented.

However, for the sake of theory if nothing else, you could do something like this.

Consider you have 5 pivot items, give your first and last PivotItem a name as

<controls:PivotItem Header="Item1" Name="first">
...

 <controls:PivotItem Header="Item5" Name="last">

Handle the Pivot's LoadingPivotItem and LoadedPivotItem events. You can then do something like this:

//class level variable we use for the current pivot
PivotItem currentItem = null;

private void Pivot_LoadingPivotItem(object sender, PivotItemEventArgs e)
{
//if the next item is going to be "first" pivot
//and the previous item was the "last" pivot...
if (e.Item == first && currentItem == last)
{
  //...reset the Pivot back to the last one.
   mainPivot.SelectedItem = last;
}

//same theory as above but checking if we're 
//sliding to the last one from the first one
if (e.Item == last && currentItem == first)
{
   mainPivot.SelectedItem = first;
}
}

private void mainPivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
{
 //once the pivot is loaded, update the currentItem
 currentItem = e.Item;
}

Hope this works.. For any queries .. revert back.



来源:https://stackoverflow.com/questions/27813196/disabling-swipe-gesture-in-windows-phone-8-1-pivot-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!