【问题标题】:Pop Up: a problem with margin Top弹出:页边距问题
【发布时间】:2011-08-05 16:15:52
【问题描述】:

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

我使用用户控件来显示一个弹出窗口:

<UserControl x:Class="XXXXXXX.Views.Lists.GameDescriptionControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    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}" Height="290" Width="460">

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}" Margin="0,0,0,0" Width="460">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="133"/>
            <RowDefinition Height="86"/>
        </Grid.RowDefinitions>
        <TextBlock HorizontalAlignment="Center" Margin="10" Name="gameDescription" Text="" VerticalAlignment="Top" TextWrapping="Wrap" Grid.Row="1" Style="{StaticResource PhoneTextTitle3Style}" />
        <Button Content="{Binding Path=AppResources.Yes, Source={StaticResource LocalizedStrings}}" Height="72" HorizontalAlignment="Left" Margin="50,5,0,0" Name="okButton" VerticalAlignment="Top" Width="160" Click="okButton_Click" Grid.Row="2" />
        <Button Content="{Binding Path=AppResources.No, Source={StaticResource LocalizedStrings}}" Height="72" HorizontalAlignment="Left" Margin="244,5,0,0" Name="cancelButton" VerticalAlignment="Top" Width="160" Click="cancelButton_Click" Grid.Row="2" />
        <TextBlock Grid.Row="0" x:Name="caption" HorizontalAlignment="Left" Margin="10" TextWrapping="Wrap" Text="{Binding Path=AppResources.Description, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextLargeStyle}"/>
    </Grid>
</UserControl>

这是显示弹出窗口的代码:

private void showInfo(int gameId)
{
    string gameDesc = getGameInfo(gameId);
    p = new Popup();
    GameDescriptionControl gd = new GameDescriptionControl();
    gd.Description = gameDesc;
    gd.OkClicked += new EventHandler(gd_OkClicked);
    gd.CancelClicked += new EventHandler(gd_CancelClicked);

    p.Child = gd;

    // Set where the popup will show up on the screen.
    p.VerticalOffset = 10;
    p.HorizontalOffset = 10;

    // Open the popup.
    p.IsOpen = true;
}

但我明白了:

如您所见,标题 TextBlock 没有顶部边距。

有什么建议吗?

【问题讨论】:

    标签: layout windows-phone-7 popup margin


    【解决方案1】:

    边距是指文本块之外的区域。如果要将文本从文本块的边缘移开,则需要使用 Padding 属性。

    【讨论】:

    • 不,我希望标题 TextBlock(带有 Text="Description")的边距 = 10。
    【解决方案2】:

    不要表现得像回形针这个词,但看起来您正在尝试制作自定义 MessageBox。

    检查此实现:http://cloudstore.blogspot.com/2011/01/customizing-messagebox-on-windows-phone.html。这是消息框的一个很好的实现,非常易于使用,外观/行为与真正的 MessageBox 非常接近,并且是轻量级的。

    添加解决方案附带的几个文件,您所要做的就是:

    private MessageBoxService mbs = new MessageBoxService();
    
        ...
    
    mbs.Closed +=new System.EventHandler(mbs_Closed);
    mbs.Show("Confirm?","Are you sure you wish to do that?",MessageBoxServiceButton.YesNo,null);
    
    void mbs_Closed(object sender, System.EventArgs e)
            {
                mbs.Closed -= mbs_Closed;
    
                if (mbs.Result == MessageBoxResult.Yes)
                {
    ...
                }
            }
    

    【讨论】:

    • 谢谢,但我想知道为什么我失去了那个利润。
    猜你喜欢
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-18
    • 2012-11-15
    • 2016-08-15
    • 2011-05-24
    相关资源
    最近更新 更多