如何捕捉webview';windows应用商店应用中的s滑动手势?
我正在构建一个windows应用商店应用程序(8.1),我使用webview控件加载html文件。我需要在代码中捕获webview的拖动/滑动事件。我该怎么做?试试这个如何捕捉webview';windows应用商店应用中的s滑动手势?,webview,windows-store-apps,Webview,Windows Store Apps,我正在构建一个windows应用商店应用程序(8.1),我使用webview控件加载html文件。我需要在代码中捕获webview的拖动/滑动事件。我该怎么做?试试这个 public MainPage() { this.InitializeComponent(); webView.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateInertia
public MainPage()
{
this.InitializeComponent();
webView.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateInertia ;
webView.ManipulationStarted += webView_ManipulationStarted;
webView.ManipulationDelta += webView_ManipulationDelta;
}
Point start;
void webView_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (e.IsInertial)
{
int threshold = 500;
if (start.X - e.Position.X > threshold) //swipe left
{
e.Complete();
//do something here
}
}
}
void webView_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
start = e.Position;
}
Tou可以使用LinqToVisualTree查找webview的边界并获取它们的事件 因此,另一个响应的代码变为:
public MainPage()
{
this.InitializeComponent();
var border = webView.Descendants<Border>().Last() as Border;
border.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateInertia ;
border.ManipulationStarted += webView_ManipulationStarted;
border.ManipulationDelta += webView_ManipulationDelta;
}
Point start;
void webView_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (e.IsInertial)
{
int threshold = 500;
if (start.X - e.Position.X > threshold) //swipe left
{
e.Complete();
//do something here
}
}
}
void webView_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
start = e.Position;
}
public主页()
{
this.InitializeComponent();
var border=webView.subjects().Last()作为边框;
border.manufactionmode=manufactionmodes.TranslateX | manufactionmodes.TranslateInertia;
border.manipationstarted+=webView_manipationstarted;
border.manufactionDelta+=网络视图_manufactionDelta;
}
起点;
void webView_操纵delta(对象发送方,操纵deltaroutedventargs e)
{
如果(例如,IsInertial)
{
int阈值=500;
if(start.X-e.Position.X>阈值)//向左滑动
{
e、 完全();
//在这里做点什么
}
}
}
void webView_manipationstarted(对象发送方,manipationstartedroutedventargs e)
{
开始=e.位置;
}
谢谢您的回复。但上述代码似乎不起作用:(我不知道为什么它对你不起作用,但对我来说效果很好。请确保你的网络视图显示在屏幕上,并且不隐藏在任何UI后面。很高兴听到它对你起作用。我不知道我在这里缺少了什么。我试着在xaml中仅使用一个网络视图,就像这样,但仍然不起作用。顺便说一句,我正在加载存储在本地存储u中的html文件。)sing webview.Navigate(新Uri(“ms-appdata:///local/path.html));您能否分享适合您的项目/解决方案?