Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Windows Phone中Pivot内嵌WebBrowser时的横向滑动处理

From Wiki
Jump to: navigation, search
WP Metro Icon UI.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
Article Metadata

代码示例
兼容于
文章
Xinx Gong 在 04 Nov 2013 创建
最后由 hamishwillee 在 18 Nov 2013 编辑

Contents

介绍

在WP的设计理念里,其实并不应该出现这种设计方式,但是作为开发人员,保不齐遇到一些变态的设计,变态的需求,所以还是需要尽最大的努力来提升一下用户体验。 Pivot中嵌套WebBrowser,最大的问题就在于用户在WebBrowser中横向滑动,Pivot却不会切换当前选中的Item。所以我们需要获取到WebBrowser的横向滑动事件,然后自己来处理Pivot的Item切换。

截获WebBrowser的手势事件

在Toolkit中,可以通过GestureService类的

public static GestureListener GetGestureListener(DependencyObject obj);

来监听WebBrowser的手势动作。 然后再通过GestureListener类的

public event EventHandler<FlickGestureEventArgs> Flick;

来获取WebBrowser的滑动事件。

处理Pivot的Item切换

获取到了WebBrowser的滑动事件后,剩下的事情就简单了。

var gesListener = GestureService.GetGestureListener(MyBrowser);
gesListener.Flick += ((sen, args) =>
{
if (args.Direction == System.Windows.Controls.Orientation.Horizontal)
{
int pivotIndex = MainPivot.SelectedIndex;
if (args.HorizontalVelocity < 0)
{
pivotIndex++;
if (pivotIndex > MainPivot.Items.Count - 1)
{
pivotIndex = 0;
}
}
else if (args.HorizontalVelocity > 0)
{
pivotIndex--;
if (pivotIndex < 0)
{
pivotIndex = MainPivot.Items.Count - 1;
}
}
MainPivot.SelectedIndex = pivotIndex;
}
});

源码下载

File:BrowserExample.zip

This page was last modified on 18 November 2013, at 01:27.
182 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×