【问题标题】:UWP XAML hide shadow behind ContentDialogUWP XAML 在 ContentDialog 后面隐藏阴影
【发布时间】:2019-10-03 21:52:15
【问题描述】:

如何摆脱 ContentDialog 背后的阴影?

对于背景,我已将背景设置为透明,但它仍然显示出来。此外,根据documentation,ContentDialog 应该有一个从 UIElement 继承的“Shadow”属性,但这似乎不是我的对话框中可用的属性,即使它是从 ContentDialog 继承的。

这是我的 XAML:

<ContentDialog
    x:Class="App.Views.HelperViews.CautionDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App.Views.HelperViews"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:control="using:App.Controls"
    mc:Ignorable="d"
    IsPrimaryButtonEnabled="False"
    IsSecondaryButtonEnabled="False"
    Padding="0"
    BorderBrush="Transparent"
    Background="Transparent"
    Loaded="ContentDialog_Loaded">

    <Grid Padding="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="228*"/>
            <RowDefinition Height="22*"/>
            <RowDefinition Height="70*"/>
        </Grid.RowDefinitions>
        <Border BorderBrush="White" BorderThickness="4" CornerRadius="3">
            <Grid Row="0"  Background="{StaticResource YellowColor2}" CornerRadius="3">
                <Grid.RowDefinitions>
                    <RowDefinition Height="100"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid Row="0" BorderBrush="{StaticResource White}" BorderThickness="0, 0, 0, 0">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20*" />
                            <ColumnDefinition Width="80*" />
                        </Grid.ColumnDefinitions>
                        <Border BorderBrush="White" BorderThickness="0 0 0 2" Grid.ColumnSpan="2" />
                        <TextBlock x:Name="Icon" Foreground="{StaticResource Black}" TextAlignment="Center" VerticalAlignment="Center" Text="{StaticResource Warning}" FontSize="50" Grid.Column="0" FontFamily="{StaticResource GlyphFontFamily}" />
                        <TextBlock x:Name="Issue" Padding="0 20 0 0" FontWeight="Bold" FontSize="{StaticResource FontSizeText3}" Grid.Column="1" Foreground="{StaticResource Black}" Text="Information only"/>
                    </Grid>
                </Grid>
                <Grid Row="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="80*" />
                        <RowDefinition Height="20*" />
                    </Grid.RowDefinitions>
                    <TextBlock x:Name="ResolveText" Grid.Row="0" Padding="20 20 20 0" FontSize="{StaticResource FontSizeText2}" TextWrapping="WrapWholeWords" Foreground="{StaticResource Black}" Text="Message text will go here. Message text will go here. Message text will go here. Message text will go here..."/>
                    <TextBlock x:Name="CodeRef" Grid.Row="1" Padding="20" FontSize="{StaticResource FontSizeText2}" Foreground="{StaticResource Black}" Text="Ref: foobar" />
                </Grid>
            </Grid>
        </Border>

        <control:WideHighlightedButton Grid.Row="2" x:Name="Zero" Margin="-4" Height="77" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
    </Grid>
</ContentDialog>

以及背后的代码:

using Windows.UI.Xaml.Controls;

namespace App.Views.HelperViews
{
    public partial class CautionDialog : ContentDialog
    {
        private string issue;
        private string resolveText;
        private string buttonText;
        private string errorCode;
        private string codeNumber;

        public CautionDialog(string code)
        {
            //Get the error dialog box strings from the resource file...
            var res = Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse("ErrorCodes");
            errorCode = code;
            issue = res.GetString(code + "_INFO");
            resolveText = res.GetString(code + "_ACTION");
            buttonText = res.GetString(code + "_BUTTON_1");
            codeNumber = "4";

            this.InitializeComponent();
        }

        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
        }

        private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
        }

        private void ContentDialog_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if (issue == null || issue == string.Empty)
            {
                Issue.Text = "No message assigned for this code!!";
            }
            else
            {
                Issue.Text = issue;
            }

            if (resolveText == null || resolveText == string.Empty)
            {
                ResolveText.Text = "Code:" + errorCode;
            }
            else
            {
                ResolveText.Text = resolveText;
            }

            if (buttonText == null || buttonText == string.Empty)
            {
                this.CloseButtonText = "Need Button!";
            }
            else
            {
                this.CloseButtonText = buttonText;
            }

            string refText = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView().GetString("Ref/Text");
            CodeRef.Text = refText + ": " + codeNumber;
        }
    }
}

【问题讨论】:

标签: xaml uwp


【解决方案1】:

如果你想禁用它,更好的方法是设置一个新的 Translation ,并使 z 值足够低。

<ContentDialog

Transition="0,0,-100">
.
.
</ContentDialog>

【讨论】:

    猜你喜欢
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多