WPF Prism - Where to put Resources?

后端 未结 3 642
死守一世寂寞
死守一世寂寞 2021-02-01 22:15

I have a prism application and various modules. I am wondering where is the best place to locate resources such as styles, brush, controltemplates, datatemplates?

Should

3条回答
  •  死守一世寂寞
    2021-02-01 22:36

    I develop application with Prism, and I use technique very close to described in Prism's manual. There is YourApplication.Infrastructure project, where you usually place all your shared interfaces etc. So:

    1. I just add project YourApplication.Resources
    2. Create there folder Themes
    3. Create separate xaml file in Themes folder for each group of resources (like Generic.WPF.xaml for standard WPF controls' styles, Generic.Brushes.xaml for brushes etc.)
    4. Create file Themes\Generic.xaml (exactly with this name, it will add huge benefits in the future) with content like

      
      
          
      
              
              
      
          
      
      
      
    5. Now you can add those resources in any module (you have separate project for it, right?) by adding reference to YourApplication.Resources to that project and adding to your view's xaml:

      
          
      
              
                  
              
      
              
      
          
      
      

    I don't know, maybe this way has some problems, but it works, and works well for me. If anybody can comment somehow this way (pros/cons) - I will be very happy to hear it!

提交回复
热议问题