“Logical resources may be of various types, such as brushes, geometries, styles, and templates.
Placing all those resources in a single file such as App.xaml hinders maintainability. A betterapproach would be to separate resources of different types (or based on some other criteria) totheir own files. Still, they must be referenced somehow from within a common file such as App.xaml so they are recognized.”为了增加资源文件的可维护性,我们应该使用ResourceDictionary对资源进行:分类、汇总。
如何实现呢?举个例子
1.新建一个WPF Application,在Application中添加一个New Item,选择ResourceDictionary。
譬如,命名为Brushes.xaml,我们用它来存放一些笔刷。打开,我们添加一个笔刷如下:
Brushes.xaml:
2.在App.xaml中Merge则个Resource。
“Open App.xaml. We need to merge external resource dictionaries into the mainapplication dictionary.”打开App.xaml,添加如下内容:
3.这样我们就可以在页面中正常使用了。
效果如下:
-----------------------------------
在实际开发中更常用的做法是:直接在使用的View内部Merge。
效果同上,如下: