【问题标题】:WebBrowser strange behaviour with margins带有边距的 WebBrowser 奇怪行为
【发布时间】:2011-08-04 21:03:26
【问题描述】:

我正在开发一个 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 有一个左边距,大于它的右边距。

更新

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

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">
...

我该如何解决这个问题?

【问题讨论】:

  • 您的Margin="0,10" 行可能与此有关。您是否尝试将其设置为单个数字以使所有边距都相同?
  • @johnhforrest:我已经改成 0 了,我也遇到了同样的问题。

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


【解决方案1】:

您的ContentPanel 网格两侧都有边距(12 像素),但右侧的边距在显示的性能计数器中并不那么明显。是这个问题吗?

【讨论】:

  • 在 VS2010 中杀死应用程序,然后在模拟器上手动运行它(类似于在手机上启动应用程序的方式)。我认为有一种方法可以以编程方式进行,这样您就不会丢失调试信息,但这是一种快速而肮脏的方法。
  • 我用一张没有性能计数器的新照片更改了我的问题。我遇到了同样的问题。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 2011-09-17
    • 1970-01-01
    • 2023-04-10
    • 2013-01-29
    • 2018-08-15
    相关资源
    最近更新 更多