简体   繁体   中英

Navigate from html page to windows 8 xaml page

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 eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM