Hello,
You could binding HTML string to Webview via Source
property.
Please refer to the following code sample:
// in your ViewModel
public HtmlWebViewSource HtmlWebViewSource {
get { return htmlWebViewSource; }
set { SetProperty(ref htmlWebViewSource, value); } }
private HtmlWebViewSource htmlWebViewSource;
// Set Html content in ViewModel
HtmlWebViewSource = new HtmlWebViewSource
{
Html = @"<HTML><BODY><H1>.NET MAUI</H1><P>Welcome to WebView.</P></BODY></HTML>"
};
// use the binding HTML content
<WebView HeightRequest="100" WidthRequest="200" Source="{Binding HtmlWebViewSource}">
</WebView>
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.