Composite WPF (Prism) module resource data templates

后端 未结 3 504
余生分开走
余生分开走 2020-12-08 03:11

Given that I have a shell application and a couple of separate module projects using Microsoft CompoisteWPF (Prism v2)...

On receiving a command, a module creates a

3条回答
  •  时光说笑
    2020-12-08 03:47

    Within the initialisation of each module, you can add to the application resources:

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

    Or if you follow a convention of each module has a resource dictionary called "Resources.xmal"...

    protected override IModuleCatalog GetModuleCatalog()
    {
        var catalog = new ModuleCatalog();
    
        AddModules(catalog,
                   typeof (Module1),
                   typeof(Module2),
                   typeof(Module3),
                   typeof(Module4));
    
        return catalog;
    }
    
    private static void AddModules(ModuleCatalog moduleCatalog,
        params Type[] types)
    {
        types.ToList()
             .ForEach(x =>
                 {
                     moduleCatalog.AddModule(x);
                     Application.Current.Resources.MergedDictionaries
                         .Add(new ResourceDictionary
                                  {
                                      Source = new Uri(string.Format(
                                                           @"pack://application:,,,/{0};component/{1}",
                                                           x.Assembly,
                                                           "Resources.xaml"))
                                  });
                  });
    }
    

提交回复
热议问题