How can I show HTML inside a Xamarin.Forms page with source for HTML in C#?

xamarin forms webview local html
xamarin forms webview example
xamarin forms webview javascript
xamarin forms webview enable javascript

I wrote this code to try and show a couple of lines of HTML within a web page:

I have this XAML:

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:Japanese;assembly=Test" 
    x:Class="Test.HelpCards" 
    x:Name="HelpCards" 
    Title="Help ▹ Cards Tab">
    <ContentPage.Content>
        <ScrollView>
            <StackLayout Spacing="10" Margin="20">
               <WebView x:Name="Browser" />
            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

    public HelpCards()
    {
        InitializeComponent();
        var htmlSource = new HtmlWebViewSource();
        htmlSource.Html = @"<html><body>
        <h1>ABC</h1>
        <p>DEF</p>
        </body></html>";
        Browser.Source = htmlSource;
    }

However when running the code I see only a blank page.

Does anyone have any ideas as to what might be wrong?

Make sure to specify layout-options for WebView.

<ContentPage.Content>
    <ScrollView> <!-- ScrollView not needed as WebView has inbuilt scrolling behavior -->
        <StackLayout Spacing="10" Margin="20">
           <WebView x:Name="Browser" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
        </StackLayout>
    </ScrollView>
</ContentPage.Content>

Xamarin.Forms WebView, some (or all) of its screens as HTML pages inside a hosted web viewer control. iOS. Displaying HTML in a UIWebView control in Xamarin.iOS also takes AXML layout file var webView = FindViewById<WebView> (Resource. When an html page is loaded into a web view, it treats the links and forms  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more How can I show HTML inside a Xamarin.Forms page with source for HTML in C#?

The webview can be in the ContentPage.Content by itself. No need to wrap it in a ScrollView or StackLayout. This method also doesn't require Horizontal or Vetical Options to be specified as well.

<ContentPage.Content>
    <WebView x:Name="Browser" />
</ContentPage.Content>

Building HTML views using Razor Templates, For a long time I have been looking for a Xaml to HTML5 solution. NET code, you can share it between the client and the server, as well as with other project types, including UWP, Xamarin, WPF, ASP.NET You can also put HTML/CSS code inside your XAML code. Open Source and Dual Licensed for peace of mind. The following demonstrates how to enable a specific domain (in this case xamarin.com) to bypass ATS requirements: XML. <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>xamarin.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.1</string> </dict> </dict> </dict> </key>.

Try this with the webBrowser

    public MainPage()
    {
        InitializeComponent();
        CheckWifiOnStart();
        CheckWifiContinously();
    }

    private void CheckWifiOnStart()
    {
        var source = new HtmlWebViewSource();
        source.BaseUrl = "file://android_asset/";


        //CONTROL TO SEE IF USER IS CONNECTED 
        if (!CrossConnectivity.Current.IsConnected)
        {
            Browser.Source = "file:///android_asset/index.html";
        }
        else
        {
            Browser.Source = "ONLINE URL";
        }
    }

    private void CheckWifiContinously()
    {
        var source = new HtmlWebViewSource();
        source.BaseUrl = "file://android_asset/";

        //CONTROL TO CONNECTIVITY CHANGE
        CrossConnectivity.Current.ConnectivityChanged += (sender, args) => {

            if (!CrossConnectivity.Current.IsConnected)
            {
                DisplayAlert("ERROR", "OFFLINE MODE", "OK");
                Browser.Source = "file:///android_asset/index.html";
            }
            else
            {
                DisplayAlert("INTERNET DETECTED", "ONLINE MODE", "OK");
                Browser.Source = "ONLINE URL";
            }          
        };
    }

    public interface IBaseUrl { string GetFile(); }

CSHTML5 (C#/XAML for HTML5), Now, Let's check how to display AlertDialog in Android Using Xamarin C#? Step resource file in the drawable directory which defines the shape of image view Tabbed Page Inside Master Detail Page Xamarin (2) UPDATE: I made some They are same as, input text field, image tag to show images, radio field in HTML. I'm developing a win-form application that needs sometime to show a "pop-up" form that displays a portion of a web page on internet (HTML). I'm getting the HTML of the page using a classic web request: var serviceRequest = new WebClient(); var response = serviceRequest.DownloadString(new Uri("www.something.com"));

Circle image in xamarin android, How To View Local Web Page Using WebView In Xamarin Android App Using Visual Studio 2015. Delpin Susai C#-->Android-->choose the Blank app (​Android). In Solution Explorer, get all the files and sources in your project. Xamarin Step 12. In this step, create HTML file. Its name is Home.Html  Android WebView is a View that allows you to display website, static HTML data, and your custom web page. Using WebView you can able to convert your web page into android application. Here I

How To View Local Web Page Using WebView In Xamarin Android , c# - Opening a website when a button on the form is clicked C#: Launch URL from inside a Duration: 4:32 Posted: May 22, 2013 Both iOS and Android have the ability to display HTML formatted strings in a built in control. These particular attributes are not available directly to Xamarin Forms, but with a quick custom renderer we can get at the functionality pretty easily. The PCL bit. We’ll start with the sample project that we started in the previous post.

C# Tutorial 63: How to open a web page with C# application , But Blazor has already started to show it has potential as a highly efficient a direct competitor to JavaScript single page application (SPA) frameworks. programming model is mixed with native Xamarin forms controls. Components authored to target these hosting models will be using HTML and CSS. Inside the Page, we will add a Layout, in the sample we use StackLayout, and inside the StackLayout, we will add the view that is a list of Controls, in this sample we used: a Label, an Entry (Input text) and a Button. Pages. Xamarin.Forms offer many possibilities of pages, allowing to propose different experiences of navigation.

Comments
  • No need for ScrollView as WebView itself has one. Also you need to specify height and width as FillAndExpand for WebView to render (at this point you see a blank page because WebView size is 0)
  • <WebView VerticalOptions=LayoutOptions.FillAndExpand HorizontalOptions=LayoutOptions.StartAndExpand ../>
  • Thanks. I tried this but for some reason I still see a blank white page. Not sure what to do next. Also tried without <StackLayout> and same thing.
  • Sorry I had set StartAndExpand in horizontal options - it was supposed to be FillAndExpand