弹出:margin Top 的问题

发布于 2024-11-01 04:04:31 字数 2669 浏览 6 评论 0原文

我正在开发一个 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;
}

但我得到了这个:

Caption without margin top

如您所见,caption TextBlock 没有 margin top。

有什么建议吗?

I'm developing a Windows Phone app.

I use a user control to show a pop up:

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

And this is the code to show the Pop Up:

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;
}

But I get this:

Caption without margin top

As you can see, caption TextBlock hasn't got a margin top.

Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟燃烟灭 2024-11-08 04:04:31

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

Margin will refer to the area outside of your textblock. If you want to move your text away from the edge of the textblock you will need to use the Padding attribute.

烟燃烟灭 2024-11-08 04:04:31

不像回形针这个词,但看起来您正在尝试制作一个自定义消息框。

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

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

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)
            {
...
            }
        }

Not to act like the word paperclip, but it looks like you're trying to make a custom MessageBox.

Check this implementation out: http://cloudstore.blogspot.com/2011/01/customizing-messagebox-on-windows-phone.html . It's a great implementation of a messagebox that is very easy to use, looks/behaves very closely to the real MessageBox, and is lightweight.

Adding the few files that come with the solution, all you have to do is:

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)
            {
...
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文