c# - 将多个资源字典动态添加到我的 WPF 项目

标签 c# wpf xaml dictionary

我需要一些有关 WPF 中资源字典的帮助。我有多个 .dll,每个 dll 中都有一个或多个资源字典。问题是我不知道 DLL 中资源字典的名称或位置。现在我正在寻找一种方法将所有这些资源字典添加到我的 Main.xaml 的代码隐藏中

也许在程序集中有一些反射?

ResourceDictionary resourceDictionary = new ResourceDictionary();
resourceDictionary.Source = new Uri("Dictionary1.xaml", UriKind.Relative);

ResourceDictionary resourceDictionary2 = new ResourceDictionary();
resourceDictionary.Source = new Uri("Dictionary2.xaml", UriKind.Relative);

resourceDictionary2.MergedDictionaries.Add(resourceDictionary);

Resources.MergedDictionaries.Add(resourceDictionary2);

但它只添加了 1 个资源词典...你能帮我吗?

最佳答案

试试这个:

ResourceDictionary resourceDictionary = new ResourceDictionary
{
     Source = new Uri("Dictionary1.xaml", UriKind.Relative)
};

ResourceDictionary resourceDictionary2 = new ResourceDictionary
{
     Source = new Uri("Dictionary2.xaml", UriKind.Relative)
};

Application.Current.Resources.MergedDictionaries.Add(resourceDictionary );
Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2 );

关于c# - 将多个资源字典动态添加到我的 WPF 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45159749/

相关文章:

c# - 如何在 C# 中使用 linq 获取多级深度订单项?

c# - 如何减少更新到 True Transparency WinForm 时的闪烁?还是有更好的方法来做到这一点?

c# - 多线程调用委托(delegate)

wpf - 当我选择一个扩展器时,复选框选中和未选中的事件被触发

windows-phone-7 - 在 Windows Phone 7 中引用合并的资源字典失败

c# - DataGridView 可编辑时 DataGridView/数据集的线程安全更新

c# - 文本框填充

wpf - x :Key ="{x:Type TextBox}" do? 是什么意思

.net - ToggleButton 在单击按钮时禁用设置 IsChecked 行为

c# - WPF MVVM 中的动态 TabControl