2011-04-14 106 views
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

正如您所看到的,標題TextBlock沒有裕量頂部。

有什麼建議嗎?

回答

0

保證金將引用您的文本塊以外的區域。如果您想要將文本從文本塊邊緣移開,則需要使用「填充」屬性。

+0

不,我想要那個標題的TextBlock(使用文本=「說明」)的保證金= 10。 – VansFannel 2011-04-14 16:08:07

0

不要像回形針一樣行動,但它看起來像你試圖製作一個自定義的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) 
      { 
... 
      } 
     } 
+0

謝謝,但我想知道爲什麼我失去了這個保證金。 – VansFannel 2011-04-15 08:07:09