如何解决ColorZone不会在WPF MaterialDesign中产生阴影
我尝试使用MaterialDesign库在WPF中制作ColorZone
。但是当我设置
materialDesign:ShadowAssist.ShadowDepth="Depth5"
它不显示任何阴影。以下是无法使用的示例应用程序的完整代码。谁能告诉我我在做什么错?
-
我在项目中添加了
MaterialDesignThemes
。 -
在
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>
- 在
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>
结果,没有阴影:
解决方法
显然 MaterialDesign 当前版本存在一些问题。我发现的唯一方法是将 Card 元素放在 ColorZone 下。在这种情况下,阴影变得可见。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。