Border for ContentDialog in Windows Phone 8.1

眉间皱痕 提交于 2019-12-13 01:28:55

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/32422445/border-for-contentdialog-in-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!