【问题标题】:Border for ContentDialog in Windows Phone 8.1Windows Phone 8.1 中 ContentDialog 的边框
【发布时间】:2015-09-06 10:18:09
【问题描述】:

我正在为 Windows Phone 8.1(Windows RT 应用程序)开发一个应用程序。 我想显示一个带有白色边框的 ContentDialog,我可以看到对话框,但我看不到其中的任何边框。 我已经为它定义了我自己的 xaml,因为我经常使用这个对话框并且我想在一个地方有通用的设置。 这是 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>

我在代码 (c#) 中使用它,如下所示:

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

我也尝试从 cs 设置边框属性,但没有任何运气。 根据 MSDN 文档,您可以为 ContentDialog 指定 BorderBrush 和 BorderThickness。 我在这里错过了什么?

【问题讨论】:

    标签: c# xaml windows-phone-8.1


    【解决方案1】:

    ContentDialog 类扩展了ContentControl,因此包含属性BorderBrushBorderThickness,但在显示时它们会被忽略。

    要创建边框,您需要指定具有边框的自定义内容,例如带有TextBlock 子元素的Border 元素:

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

    【讨论】:

    • 谢谢。 +1 为您,-1 为 MSDN 误导 API 文档
    • 如果我有在 xaml 中生成的内容并且只想删除边框怎么办?因为我不想在 c# 中创建整个 xaml
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多