我正在尝试在我的WPF类库(.NET框架)中使用MaterialDesignXamlToolkit。我正在遵循他们官方的快速入门教程,但由于我没有App.xaml文件,所以我必须进行一些调整。显然某个步骤出错了,但我不知道是哪一个。
1)我使用Nuget安装了MaterialDesignXamlToolkit。
2)我创建了ResourceDictionary,并使用以下代码指定了键(如果我不这样做会出现错误)。
如果我删除
1)我使用Nuget安装了MaterialDesignXamlToolkit。
2)我创建了ResourceDictionary,并使用以下代码指定了键(如果我不这样做会出现错误)。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary x:Key="123">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary>
如果我删除
<ResourceDictionary x:Key="123">
元素,则会出现错误:System.Windows.Markup.XamlParseException: Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
FileNotFoundException: Could not load file or assembly 'MaterialDesignThemes.Wpf, Culture=neutral' or one of its dependencies.
3)我的“主屏幕”是页面,因此我将资源添加到该页面:
<Page.Resources>
<ResourceDictionary Source="/MyAsembly;component/ResourceDictionary/MaterialDesign.xaml" />
</Page.Resources>
4) 显而易见的问题出现在这里(这是官方教程的第二步):我将以下代码添加到我的页面:
<Page ...
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}">
但我收到一个警告: 无法解析资源{MaterialDesignBody,MaterialDesignPaper,MaterialDesignFont}。
我尝试了一些解决方案,指出ResourceDictionary的构建操作应该是页面,并且它确实是。
任何帮助都将不胜感激!