ColorZone不会在WPF MaterialDesign中产生阴影

问题描述

我尝试使用MaterialDesign库在WPF中制作ColorZone。但是当我设置

materialDesign:ShadowAssist.ShadowDepth="Depth5"

不显示任何阴影。以下是无法使用的示例应用程序的完整代码。谁能告诉我我在做什么错?

  1. 我在项目中添加MaterialDesignThemes

  2. app.xaml中粘贴:

<Application
    x:Class="TestShadow.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestShadow"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    StartupUri="MainWindow.xaml">

    <Application.Resources>
        <ResourceDictionary>
            
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme
                    BaseTheme="Light"
                    PrimaryColor="DeepPurple"
                    SecondaryColor="Lime" />
                <ResourceDictionary
                    Source="pack://application:,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
            
        </ResourceDictionary>
    </Application.Resources>
</Application>
  1. MainWindow.xaml中我添加了:
<Window
    x:Class="TestShadow.MainWindow"
    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"
    xmlns:local="clr-namespace:TestShadow"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    mc:Ignorable="d"
    Title="MainWindow"
    Height="450"
    Width="800">

    <Grid>

        <materialDesign:ColorZone
            Mode="PrimaryDark"
            Padding="16"
            materialDesign:ShadowAssist.ShadowDepth="Depth5">

            <TextBlock
                Text="Material Design In XAML Toolkit"
                VerticalAlignment="Center" />

        </materialDesign:ColorZone>

    </Grid>
    
</Window>

结果,没有阴影:

result

解决方法

显然 MaterialDesign 当前版本存在一些问题。我发现的唯一方法是将 Card 元素放在 ColorZone 下。在这种情况下,阴影变得可见。