0

Prolog:私はc#/xamlプロジェクトを持っています。このプロジェクトでは、MainPageにMainWebViewを含む2つのページ(MainPage.xamlとSecondExamplePage)があります。mainPage.xaml.csに、簡単なコードがあります。

 protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        MainWebView.Source = new Uri("ms-appx-web:///assets/physics/index.html");
    }

ユーザーがアプリを起動すると、たとえば1つの画像でhtmlページ(index.html)が表示され、それがすべてです(私は今、それは間違った方法ですが、顧客はこれを望んでいます)。

必要な作業:ユーザーが(index.htmlページの)画像をクリックすると、SecondExamplePage.xamlに移動する必要があります。どうすればよいですか?WebView.ScriptNotifyとWebView.InvokeScriptについてリードしましたが、このメソッドがどのように機能するのかわかりません。

4

1 に答える 1

1

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 View Controlサンプルは、ここでも役立つ場合があります。

于 2013-03-16T05:25:58.107 に答える