Reputation: 151
Prolog: I have c#/xaml project. In this project i have two pages (MainPage.xaml, and SecondExamplePage) with MainWebView on MainPage. On mainPage.xaml.cs i have simple code:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MainWebView.Source = new Uri("ms-appx-web:///assets/physics/index.html");
}
When user start app, he see html page(index.html) for e.g with one image, it's all.(i now, that is the wrong way, but customer want this).
What i need to do: When user clicked on image(on index.html page), i'm need to navigate on SecondExamplePage.xaml How can i do that? I reed about WebView.ScriptNotify and WebView.InvokeScript, but i don't understand how work this methods.
Upvotes: 0
Views: 711
Reputation: 23764
In your HTML page, your image tag would look something like this:
<img src="./image.png" onclick="external.notify('gotoPage2')" />
In your C# code:
public MainPage()
{
this.InitializeComponent();
MainWebView.ScriptNotify += WebView_ScriptNotify;
}
void MainWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
if (e.Value == "gotoPage2")
this.Frame.Navigate(typeof(Page2));
}
The XAML Web View Control sample may help you here as well.
Upvotes: 1