且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XAML WebView绑定到字符串在Xamarin Forms中不起作用

更新时间:2022-11-11 20:42:01

您使用的是错误的,使用HtmlWebViewSource时,您需要指定实际的HTML而不是要转到的URL.如果要导航到URL,请在Source属性中指定它.

You're using it wrong, when using the HtmlWebViewSource you need to specify actual HTML instead of the URL where you want to go to. If you want to navigate to a URL, specify it in the Source property.

如果要绑定它,则必须实现类似这样的东西.

If you want to bind it, you have to implement something like this.

在您的视图模型中创建一个字符串属性:

In your view model create a string property:

public string UrlToGoTo { get; set; }

然后像平常一样设置它,确保以某种方式实现了INotifyPropertyChanged.

Then set it like you normally would, make sure to have INotifyPropertyChanged is implemented somehow.

然后,像这样连接您的WebView:

Then, wire up your WebView like this:

<WebView Source="{Binding UrlToGoTo}"
    HeightRequest= "300"
    WidthRequest="250"
    Navigated="Handle_Navigated"
    VerticalOptions="FillAndExpand"
    AbsoluteLayout.LayoutFlags="All"
    AbsoluteLayout.LayoutBounds="0,0,1,1" />