如何在windows phone应用程序中基于手势进行导航?
在我的应用程序中,我有一个主页和另外两个页面,所以我想从一个页面导航到另一个页面,反之亦然。当我从右向左水平滑动时,当我从左向右水平滑动时,它应该导航到主页 假设,我们在从右向左滑动的主页上(主页-->Page1,再次滑动-->Page2,再次滑动-->Page1…像那样…),并且在所有页面上,如果我从左向右滑动,它应该被导航到主页。如何在windows phone 8应用程序中执行此操作 我的代码:如何在windows phone应用程序中基于手势进行导航?,windows,windows-phone-8,gesture-recognition,Windows,Windows Phone 8,Gesture Recognition,在我的应用程序中,我有一个主页和另外两个页面,所以我想从一个页面导航到另一个页面,反之亦然。当我从右向左水平滑动时,当我从左向右水平滑动时,它应该导航到主页 假设,我们在从右向左滑动的主页上(主页-->Page1,再次滑动-->Page2,再次滑动-->Page1…像那样…),并且在所有页面上,如果我从左向右滑动,它应该被导航到主页。如何在windows phone 8应用程序中执行此操作 我的代码: if (e.HorizontalVelocity < 0) //when it is t
if (e.HorizontalVelocity < 0) //when it is true it should navigate to next index value
{
try
{
Pivot_Main.SelectedIndex++;// here every time it's showing the same index value it is not incrementing
switch (Pivot_Main.SelectedIndex)
{
case 0:
Pivot_Main.SelectedIndex = 0;
txtBlock_Pivot_Heading.Text = "Temperature";
var brush = new SolidColorBrush(Color.FromArgb(0xFF, 0x8C, 0xC6, 0x3F));
b_celcius = true;
temperature_Page_Clear();
txtBlock_OptText.Text = "ºC";
btn_OptText.Content = "ºC";
Grid_PivotHeading.Background = brush;
Canvas_Home.Background = brush;
Canvas_DisplayName.Width = 55;
// btn_OptText.SetValue(Canvas.LeftProperty, 380.0);
break;
case 1:
Pivot_Main.SelectedIndex = 1;
txtBlock_Pivot_Heading.Text = "Length";
length_Page_Clear();
b_meter = true;
}
}
}
if(e.HorizontalVelocity<0)//如果为true,则应导航到下一个索引值
{
尝试
{
Pivot_Main.SelectedIndex++;//这里每次显示相同的索引值时,它都不会递增
开关(主枢轴。选择索引)
{
案例0:
Pivot_Main.SelectedIndex=0;
txtBlock\u Pivot\u Heading.Text=“温度”;
var brush=新的SolidColorBrush(Color.FromArgb(0xFF,0x8C,0xC6,0x3F));
b_celcius=真;
温度页面清除();
txtBlock_OptText.Text=“ºC”;
btn_OptText.Content=“ºC”;
Grid_PivotHeading.Background=画笔;
Canvas_Home.Background=画笔;
Canvas_DisplayName.Width=55;
//btn_OptText.SetValue(Canvas.LeftProperty,380.0);
打破
案例1:
Pivot_Main.SelectedIndex=1;
txtBlock\u Pivot\u Heading.Text=“长度”;
长度页面清除();
b_米=真;
}
}
}
请帮助我,真诚的帮助是感激的 这里有多个选项 如果您可以在一个页面中完成操作,那么
Pivot
或Panorama
控件就足够了
此外,如果您需要每个页面都应该不同,并且希望使用NavigationService.Navigate()
从一个页面转到另一个页面,那么您有一个名为Flick
的事件。您可以通过该事件的HorizontalVelocity
和VerticalVelocity
来处理左/右滑动
要使用Flick手势,您需要在xaml w.r.t.中将以下代码添加到UI元素:
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="OnFlick"/>
</toolkit:GestureService.GestureListener>
在.cs及其处理程序中:
private void OnFlick(object sender, FlickGestureEventArgs e)
{
// User flicked towards left
if (e.HorizontalVelocity < 0)
{
//your respective navigation to other page
}
// User flicked towards right
if (e.HorizontalVelocity > 0)
{
//your respective navigation to other page
}
private void OnFlick(对象发送方,FlickGestureEventArgs e)
{
//用户向左轻弹
如果(如水平速度<0)
{
//您各自的导航到其他页面
}
//用户向右轻弹
如果(如水平速度>0)
{
//您各自的导航到其他页面
}
您可以获得的手势支持详细信息这可能不是最好的解决方案,但带有空白标题的Pivot控件可以提供这种效果。当我快速滑动时,它可以正常工作,但如果我在页面上缓慢滑动,它的响应不正确。如果您不在两者之间停止,则它应该能够识别Flick事件。无论如何,您也可以使用drag eve你终于可以试试了。