WebBrowser带边距的奇怪行为

时间:2011-04-13 16:24:11

标签: layout windows-phone-7 webbrowser-control margin

我正在开发一个Windows Phone应用程序。

我有一个带有以下XAML代码的用户控件:

<UserControl x:Class="XXXXXXX.Views.SignIn.FacebookControl"
    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: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}"
    d:DesignHeight="768" d:DesignWidth="480">

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
        <!--ContentPanel. Colocar aquí el contenido adicional-->
        <Grid x:Name="ContentPanel" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <TextBlock
                Grid.Row="1" 
                Height="30" 
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Visibility="Visible" 
                Margin="10"
                Name="LoadingText"
                Text="{Binding Path=AppResources.BrowserNavigating, Source={StaticResource LocalizedStrings}}"/>
            <phone:WebBrowser
                Grid.Row="0"
                Name="FacebookLoginBrowser"
                IsScriptEnabled="True"
                Height="607"
                VerticalAlignment="Top"
                HorizontalAlignment="Stretch"
                Margin="0,10"
                Navigated="FacebookLoginBrowser_Navigated"
                Loaded="FacebookLoginBrowser_Loaded"
                Navigating="FacebookLoginBrowser_Navigating"/>
        </Grid>

    </Grid>
</UserControl>

我是这样的:

WebBrowser margin error

WebBrowser左边距,大于右边距。

更新

这就是我嵌入用户控件的方式:

facebookControl = new FacebookControl();
facebookControl.SetValue(Grid.RowSpanProperty, 2);
facebookControl.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
facebookControl.VerticalAlignment = System.Windows.VerticalAlignment.Top;
facebookControl.Margin = new Thickness(0);
facebookControl.Height = 768;
facebookControl.Width = 480;
ContentPanel.Children.Add(facebookControl);

这是ContentPanel的定义:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
...

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

您的ContentPanel网格两侧都有边距(12px),但右边的边距不显示性能计数器。这是问题吗?

答案 1 :(得分:0)

边距不平衡,因为您明确设置宽度。不要在facebookControl上专门设置宽度 Horizo​​ntalAlignment ,它应该填充可用空间并在视觉上保持平衡。