我将一个WebBrowser控件放在pivotItem中,并且出现问题,WebBrowser控件接管轻弹手势。因此枢轴无法正常导航。所以我在父容器中放了一个gestureListner。
<ScrollViewer Grid.Row="1"
VerticalScrollBarVisibility="Auto">
<phone:WebBrowser x:Name="myWB1"
FontSize="{StaticResource PhoneFontSizeExtraLarge}"
wb:WebBrowserHtmlBinding.HtmlString="{Binding MainFloor}"
Foreground="{StaticResource TitleColor}"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Top"
Width="Auto" Height="Auto"
Navigating="WebBrowser_Navigating">
</phone:WebBrowser>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="GestureListener_Flick" />
</toolkit:GestureService.GestureListener>
</ScrollViewer>
private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
{
if (e.Direction.ToString() == "Horizontal")
{
myPivot.SelectedIndex = 1;
}
}
上面的代码有效,但问题是它总是在一个方向导航。无论我向右还是向左轻弹。枢轴始终从右向左导航。为什么,以及如何解决它? [pivotitem的WebBrowser控件的SelectedIndex为0,下一个透视为1.]
答案 0 :(得分:0)
您没有检查轻弹是向左还是向右。你只是检查方向,如果是水平的,它可以是左或右。试试这个:
private void GestureListener_Flick(object sender, FlickGestureEventArgs e) {
if (e.Direction == System.Windows.Controls.Orientation.Vertical) return;
var currentIndex = myPivot.SelectedIndex;
var maxIndex = myPivot.Items.Count - 1;
// User flicked towards left
if (e.HorizontalVelocity < 0) {
if (currentIndex < maxIndex) myPivot.SelectedIndex++; else myPivot.SelectedIndex = 0;
// User flicked towards right
} else if (e.HorizontalVelocity > 0) {
if (currentIndex > 0) myPivot.SelectedIndex--; else myPivot.SelectedIndex = maxIndex;
}
}
或者,您只需在浏览器控件上将IsHitTestVisible
设置为false
即可禁用其上的手势。