Search code examples
c#xamlwindows-phone-8webviewwindows-phone-8.1

How to stretch the height of a webview in windows phone 8.1?


I got a page where I have a grid within a textblock and a webview.

I can't find a way to let the webview filling the page, event with the "*" or the horizontal strech.

I had to put a minHeight to see the webview because if I set no height, it's not visible (I guess height is 0).

<ScrollViewer x:Name="scrollViewer" >
        <Grid  >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" x:Name="title" MaxLines="1" TextTrimming="CharacterEllipsis" Margin="10" TextAlignment="Left" TextWrapping="Wrap" Foreground="Black" FontSize="30" FontWeight="Bold"/>
            <StackPanel Grid.Row="1" Background="Black"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <WebView MinHeight="600"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Stretch"
                         ScrollViewer.ZoomMode="Disabled"
                         x:Name="webview"  
                         Margin="10" />
            </StackPanel>
        </Grid>
    </ScrollViewer>

Here is my cs code

webview.NavigateToString("<HEAD>" +
                    "<style type=\"text/css\">body{color: #fff; background-color: #000; overflow-x: hidden;" + fontSize + "}</style>" +
                    "<TITLE>title</TITLE></HEAD><BODY>" + text + "</BODY>");

Thank you for your help.


Solution

  • Try remove the stackpanel & set the Height to Auto

    <ScrollViewer x:Name="scrollViewer">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" x:Name="title" MaxLines="1"
                       TextTrimming="CharacterEllipsis"
                       Margin="10" TextAlignment="Left"
                       TextWrapping="Wrap" Foreground="Black" 
                       FontSize="30" FontWeight="Bold" />
            <Grid Background="Black"
                  Margin="10"
                  Grid.Row="1">
                <WebView ScrollViewer.ZoomMode="Disabled"
                         x:Name="webview"  
                         Margin="10" 
                         Height="Auto" />
            </Grid>
        </Grid>
    </ScrollViewer>