WPF棱镜 - 如果把资源呢? [英] WPF Prism - Where to put Resources?

查看:125
本文介绍了WPF棱镜 - 如果把资源呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个棱镜的应用程序和各种模块。我想知道在哪里找到的资源,如样式,刷,CONTROLTEMPLATES,的DataTemplates最好的地方?

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 I make one single resource dictionary and put everything there? Should each module have their own resources? Or each view? I would like to follow the Prism goal of keeping everything modular, but also I dont see the point in re-declaring the same resources in every module...

推荐答案

我发展与应用棱镜,我用的技术非常接近棱镜的手册中描述。有YourApplication.Infrastructure项目,在这里你平时把你的所有共享接口等,所以:

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. 我只是添加项目YourApplication.Resources

  2. 创建文件夹有主题

  3. 在主题创建单独的XAML文件夹中的每个组的资源(如Generic.WPF.xaml标准WPF控件的风格, Generic.Brushes.xaml画笔等)

  4. 创建文件Themes\Generic.xaml(正好与这个名字,它将在未来增加巨大的利益)与内容,如

  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

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>

        <ResourceDictionary Source="Generic.Brushes.xaml"/>
        <ResourceDictionary Source="Generic.WPF.xaml"/>

    </ResourceDictionary.MergedDictionaries>

</ResourceDictionary>


  • 现在,你可以在任何模块中添加这些资源(你必须为它单独的项目,右?)加入参考YourApplication.Resources该项目并添加到您的视图的XAML:

  • 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:

    <UserControl.Resources>
        <ResourceDictionary>
    
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/YourApplication.Resources;component/Themes/Generic.xaml"/>
            </ResourceDictionary.MergedDictionaries>
    
            <!-- Put your not shared resource here -->
    
        </ResourceDictionary>
    </UserControl.Resources>
    


  • 我不知道,也许这种方式有一些问题,但它的工作原理,并很适合我。如果有人能以某种方式发表意见这种方式(优点/缺点) - !我会很高兴听到这个消息。

    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!

    这篇关于WPF棱镜 - 如果把资源呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆