Search code examples
webviewwindows-store-appswindows-8.1

WebView inside HubSection does not render page


I have a WebView inside a HubSection in a Hub control:

<HubSection x:Name="details_section" ...>
    <!-- ... -->
    <DataTemplate>    
         <WebView x:Name="webView" VerticalAlignment="Stretch" Margin="0" Height="300"  />
    </DataTemplate>
</HubSection>

The problem is that, when I make it navigate to an HTML string, it does not render the content.

// I adjusted and simplified the code
WebView wv = elem.FindName("webView") as WebView;
if (wv != null) {
    wv.NavigateToString(detailTemplate);
}

Of course I debugged to see that the method actually gets called. Moreover, the LoadCompleted event gets called as well.

The problem is not due to bad HTML code as I tested with plain "<html><body>hello</body></html>".


Solution

  • I solved this issue by using the following extension: https://github.com/timheuer/callisto/blob/master/src/Callisto/Extensions/WebViewExtension.cs

    Use:

    <ns:MyPage
    xmlns:ns="using:mylib" 
    xmlns:ext="using:WSLibrary.Extensions" ...>
       <!-- ... -->
       <HubSection x:Name="details_section" ...>
          <!-- ... -->
          <DataTemplate>    
              <WebView ext:WebViewExtensions.HtmlSource="{Binding MyHtmlString}" ... />
         </DataTemplate>
       </HubSection>
       <!-- ... -->
    </ns:MyPage>