Prolog:我有c#/xaml项目。在这个项目中,我有两个页面(MainPage.xaml和SecondExamplePage)和MainWebView on MainPage。在mainPage.xaml.cs上,我有简单的代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MainWebView.Source = new Uri("ms-appx-web:///assets/physics/index.html");
}当用户启动应用程序时,他看到了html页面(index.html),比如只有一个图片。(我现在,这是错误的方式,但客户想要这个)。
我需要做的是:当用户点击图片(在index.html页面上)时,需要在SecondExamplePage.xaml上导航--我如何才能做到这一点?I reed关于WebView.ScriptNotify和WebView.InvokeScript,但我不明白如何使用这些方法。
发布于 2013-03-16 05:25:58
在HTML页面中,图像标记应该如下所示:
<img src="./image.png" onclick="external.notify('gotoPage2')" />在您的C#代码中:
public MainPage()
{
this.InitializeComponent();
MainWebView.ScriptNotify += WebView_ScriptNotify;
}
void MainWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
if (e.Value == "gotoPage2")
this.Frame.Navigate(typeof(Page2));
}在这里,XAML Web视图控件示例也可以帮助您。
https://stackoverflow.com/questions/15427996
复制相似问题