【问题标题】:Load dynamically a ResourceDictionnary [duplicate]动态加载 ResourceDictionnary [重复]
【发布时间】:2014-12-23 10:23:23
【问题描述】:

我遇到了一些问题。我希望我的应用在 app.xaml.cs 中动态加载 ResourceDictonnary。

这是我目前的代码:

ResourceDictionary theme = XamlReader.Load(???);
Resources.MergedDictionaries.Add(theme);

问题是,如何从 xaml 文件中获取 ResourceDictionnary 流?我不想用 exe 复制 xaml 文件。它的构建操作设置为 Page,我想加载它。

你能告诉我怎么做吗?

谢谢!

【问题讨论】:

    标签: c# wpf xaml resourcedictionary xamlreader


    【解决方案1】:

    尝试使用以下代码(我从我的 IModule.Initialize 中调用它)

     Application.Current.Resources.MergedDictionaries
                .Add(new ResourceDictionary
                {
                    Source = new Uri(@"pack://application:,,,/My.Application;component/Resources/Resources.xaml")
                });
    

    查看附图中的项目树:

    【讨论】:

      猜你喜欢
      • 2011-11-09
      • 2014-01-22
      • 2013-01-09
      • 2013-05-24
      • 2020-04-17
      • 2020-04-19
      相关资源
      最近更新 更多