开发者

Pop Up: a problem with 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.R开发者_如何学CowDefinitions>
            <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:

Pop Up: a problem with margin Top

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

Any advice?


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜