简体   繁体   中英

Border for ContentDialog in Windows Phone 8.1

I am developing an application for Windows Phone 8.1 (Windows RT apps). I'd like to show a ContentDialog with a white border around it, and I can see the dialog all right, but I am not able to see any border in it. I have defined my own xaml for it, since I use this dialog frequently and I wanted to have common settings in one place. Here is the XAML:

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

I am using it from code (c#) like this:

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

I have tried to set the border properties from cs as well, but without any luck. Based on the MSDN documentation you can specify the BorderBrush and BorderThickness for ContentDialog. What am I missing here?

The ContentDialog class extends ContentControl and therefore contains properties BorderBrush and BorderThickness , but when displayed they are ignored.

To create a border you need to specify custom content that has a border, for example a Border element with a TextBlock as its child:

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM