locked
How to load html content using webview?

    Question

  • Hi,

    I want to display html content inside a settings flyout.

    XAML Code:

           

    <SettingsFlyout
        x:Class="ABC.Settings.Ack"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:SMDWindowsClient.Settings"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        IconSource="Assets/SmallLogo.png"
        Title="Ack"
        d:DesignWidth="346">

        <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="641" >

            <StackPanel Style="{StaticResource SettingsFlyoutSectionStyle}">
            <Button Content="Button" Click="Onclick"   HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
            <WebView x:Name="AckWebView" 
    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

    </StackPanel>
        </StackPanel>
    </SettingsFlyout>

                

     private void Onclick(object sender, RoutedEventArgs e)
            {
                AckWebView.NavigateToString(@" <html>
                            <head></head>
                             <body>
                              <div id='myDiv'>Welcome to this WORLD</div>
                             </body>
                          </html>");

            }

    When I open the Settings flyout, it shows a blank page with only the title of the flyout.

    The HTML content is not getting displayed.

    How can i solve this issue?

    Tuesday, May 12, 2015 9:37 AM

Answers

  • You have to give the WebView a height and width if you're going to put it inside a StackPanel. StackPanels squish controls to as small as they can get it.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by VDNS Wednesday, May 13, 2015 5:27 AM
    Tuesday, May 12, 2015 3:49 PM
    Moderator

All replies

  • You have to give the WebView a height and width if you're going to put it inside a StackPanel. StackPanels squish controls to as small as they can get it.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by VDNS Wednesday, May 13, 2015 5:27 AM
    Tuesday, May 12, 2015 3:49 PM
    Moderator
  • Thanks a lot 
    Wednesday, May 13, 2015 5:27 AM