Search code examples
windows-phone-8webbrowser-controlviewbox

Why WebBrowser is not shown in a ViewBox on Windows Phonw 8?


I am trying to display a browser in a ViewBox element on a Windows Phone 8 Nokia Lumia.

The WebBrowser is displaying when it is alone, but when I put it in a ViewBox element, it does not show.

Here is my sample code:

<phone:PhoneApplicationPage
    x:Class="PhoneApp2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->

    <Viewbox Stretch="Fill" >

        <phone:WebBrowser Source="http://google.com" />
    </Viewbox>

</phone:PhoneApplicationPage>

Solution

  • hey the problem is the default height and width of viewbox control..just set the height and width of your view box control ..like this it will work..

    <Viewbox Grid.Row="0"  VerticalAlignment="Top" HorizontalAlignment="Left">
            <phone:WebBrowser Grid.Row="0" Height="800" Source="http://www.google.com" Width="500" />
        </Viewbox>
    

    any query..comment below..