locked
Image not display From HtmlLabel . RRS feed

  • Question

  • User366227 posted

    Image not Display from htmllabel .i want to show both label and image from html source code. It display both label and image in case of webview but image not fit in page its taking huge space in both horizontally and vertically .how to fix this problem please help I stack from last 2 days.

    Thursday, October 17, 2019 6:24 AM

Answers

  • User382871 posted

    Change image's property in html. Set the image's style attribute to specify the width and height of an image. ``` public Page1() { var browser = new WebView(); 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' style='width: 100%; height: 150px; '/>
                        <p><a href=""local.html"">next page</a></p>
                        </body>
                        </html>";
    
    htmlSource.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
    browser.Source = htmlSource;
    Content = browser;
    

    } ```

    Tutorial about Xamarin.Forms WebView: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows#local-html-content

    Article on HTML Images: https://www.w3schools.com/html/html_images.asp

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, October 17, 2019 9:37 AM

All replies

  • User382871 posted

    Change image's property in html. Set the image's style attribute to specify the width and height of an image. ``` public Page1() { var browser = new WebView(); 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' style='width: 100%; height: 150px; '/>
                        <p><a href=""local.html"">next page</a></p>
                        </body>
                        </html>";
    
    htmlSource.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
    browser.Source = htmlSource;
    Content = browser;
    

    } ```

    Tutorial about Xamarin.Forms WebView: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows#local-html-content

    Article on HTML Images: https://www.w3schools.com/html/html_images.asp

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, October 17, 2019 9:37 AM
  • User366227 posted

    @Jarvan thanks you I succeed .

    Thursday, October 17, 2019 12:24 PM