【问题标题】:ColorZone doesn't drop shadow in WPF MaterialDesignColorZone 不会在 WPF MaterialDesign 中投影
【发布时间】:2021-01-22 20:05:26
【问题描述】:

我尝试使用 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>

结果,没有阴影:

【问题讨论】:

  • 您使用哪个版本的 Material Design?
  • MaterialDesignThemes - 3.2.0。 MaterialDesignColors - 1.2.7
  • 阴影在 ColorZone 之外,因此您可以尝试为 ColorZone 添加一个边距,以检查它是否被其他内容隐藏。 Margin="5" 应该足够了。如果可行,请尝试将颜色区域放在第一个计划上,以确保阴影覆盖其他内容
  • @XimazeC 我添加了边距,但我仍然看不到任何阴影。我发现这样做的唯一方法是使用 Card 并将 Radius 设置为 0
  • 我也有这个问题,它在以前的项目中工作,但现在不是。

标签: c# wpf material-design material-design-in-xaml


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 2021-02-24
    • 2020-06-26
    • 1970-01-01
    相关资源
    最近更新 更多