【发布时间】:2023-03-04 13:57:01
【问题描述】:
我创建了一个包含一些常用画笔的资源字典。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="GrayColor1" Color="#f2f2f2"/>
<SolidColorBrush x:Key="GrayColor2" Color="#e5e5e5"/>
<SolidColorBrush x:Key="GrayColor3" Color="#d9d9d9"/>
...
</ResourceDictionary>
我想在自定义控件库中的许多控件中使用它们,但我没有找到任何方法使它们可用于控件。
在普通应用程序中,我会将它们放在 App.xaml 中,但在库中没有 App.xaml 文件。
那么库中资源字典的使用方法是什么?
我已经尝试将字典合并到 /Themes/Generic.xaml 中,但没有成功:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyControls;component/DefaultBrushes.xaml"/>
<ResourceDictionary Source="/MyControls;component/Styles/CustButton.xaml"/>
<ResourceDictionary Source="/MyControls;component/Styles/CustTextBox.xaml"/>
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
但是引用资源会导致空引用(似乎在 Generic.xaml 中只能合并控件模板)。
【问题讨论】:
标签: wpf dictionary dll custom-controls resourcedictionary