[英]Navigate from html page to windows 8 xaml page
Prolog:我有c#/ xaml項目。 在這個項目中,我有兩個頁面( MainPage.xaml和SecondExamplePage ),其中MainPage包含MainWebView。 在mainPage.xaml.cs上,我有簡單的代碼:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MainWebView.Source = new Uri("ms-appx-web:///assets/physics/index.html");
}
當用戶啟動應用程序時,他看到的是html頁面(index.html),例如帶有一個圖像,僅此而已。(我現在,這是錯誤的方式,但是客戶希望這樣做)。
我需要做的是:當用戶單擊image(在index.html頁上)時, 我需要在SecondExamplePage.xaml上導航,我該怎么做? 我曾經談論過WebView.ScriptNotify和WebView.InvokeScript,但是我不了解這種方法的工作方式。
在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視圖控件示例也可以在這里為您提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.