2015-09-06 38 views
1

我正在爲Windows Phone 8.1(Windows RT應用程序)開發應用程序。 我想顯示一個帶有白色邊框的ContentDialog,並且我可以看到對話框正確,但我無法看到它的任何邊框。 我已經爲它定義了我自己的xaml,因爲我經常使用這個對話框,並且我想在一個地方有共同的設置。 這裏是XAML:Windows Phone 8.1中ContentDialog的邊框

<ContentDialog 
    x:Class="MyNamespace.MyDialog" 
    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" 
    Margin="10,330,10,0" 
    Height="200" 
    Width="340" 
    Padding="10" 
    Background="Black" 
    BorderBrush="White" 
    BorderThickness="10"> 
</ContentDialog> 

我使用它的代碼(C#)是這樣的:

mPopup = new MyDialog() 
{ 
    Title = "", 
    Content = "Hello World", 
    PrimaryButtonText = "OK", 
    IsSecondaryButtonEnabled = false, 
}; 
mPopup.ShowAsync(); 

我試圖設置從CS邊框屬性爲好,但沒有任何的運氣。 基於MSDN文檔,您可以爲ContentDialog指定BorderBrush和BorderThickness。 我在這裏錯過了什麼?

回答

3

ContentDialog類擴展ContentControl並且因此包含屬性BorderBrushBorderThickness,但顯示時它們將被忽略。

要創建需要指定具有邊框自定義內容的邊框,例如Border元素與TextBlock作爲其子:

var mPopup = new ContentDialog() 
{ 
    Title = "", 
    PrimaryButtonText = "OK", 
    IsSecondaryButtonEnabled = false, 
    Content = new Border() 
    { 
     HorizontalAlignment = HorizontalAlignment.Stretch, 
     BorderThickness = new Thickness(10), 
     BorderBrush = new SolidColorBrush(Colors.White), 
     Child = new TextBlock() 
     { 
      Text = "Hello World", 
      FontSize = 20, 
      Foreground = new SolidColorBrush(Colors.White), 
      HorizontalAlignment = HorizontalAlignment.Left, 
      VerticalAlignment = VerticalAlignment.Top 
     } 
    } 
}; 

mPopup.ShowAsync(); 
+0

感謝。對你來說是+1,對MSDN來說是-1對於誤導性的API文檔 –

+0

如果我有在xaml中生成的內容並且想刪除邊界怎麼辦?因爲我不想在c#中創建整個xaml – AbsoluteSith