Xamarin表示Webview导航事件

时间:2017-09-11 13:34:22

标签: xamarin xamarin.forms

我有一个PCL项目,最近将Xamarin表单更新到版本2.3.4.270,但似乎在更新到此版本后,webview.navigated()事件不会触发。

var browser = new BaseUrlWebView (); 
var htmlSource = new HtmlWebViewSource ();

    htmlSource.Html = @"<html>
        <head>
        <link rel=""stylesheet"" href=""default.css"">
        </head>
        <body>
        <h1>Xamarin.Forms</h1>
        <p>The CSS and image are loaded from local files!</p>
        <img src='XamarinLogo.png'/>
        <p><a href=""local.html"">next page</a></p>
        </body>
        </html>";

    htmlSource.BaseUrl = DependencyService.Get<IBaseUrl> ().Get ();

    browser.Navigated += (sender, e) => {
        this.DisplayAlert("Navigated", "Navigated the page", "Cancel");
    };

    browser.Source = htmlSource;


    Content = browser;

1 个答案:

答案 0 :(得分:0)

var browser = new BaseUrlWebView();

var htmlSource = new HtmlWebViewSource();

htmlSource.Html = @“某些HTML”;

htmlSource.BaseUrl = DependencyService.Get()。Get();

browser.Source = htmlSource;

browser.Navigated + = WebViewOnNavigated;

内容=浏览器;

private async void WebViewOnNavigated(object sender,WebNavigatedEventArgs e){

 await DisplayAlert("Navigated", "Navigated the page", "Cancel");

}