WPF自定义控件库和普通类库的区别? [英] Differences between WPF Custom Control Library and plain Class Library?

查看:74
本文介绍了WPF自定义控件库和普通类库的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前我发布了一个关于跨程序集共享资源词典的问题.事实证明,您可以使用 Component Resource Key 标记扩展来做到这一点.当时,我只能在 WPF 自定义控件项目中使用它,而不能与普通的类库项目一起使用.

I posted a question a few months ago about sharing resource dictionaries across assemblies. It turns out you can do that using the Component Resource Key markup extension. At the time, I could only get it working with a WPF Custom Control project, not with a plain Class Library project.

现在我需要使用现有的普通类库项目来托管共享资源字典.这意味着我需要改造类库项目以支持组件资源密钥标记扩展.我已经向类库项目添加了一个 Themes 文件夹和一个 Generic.xaml 资源字典文档,以及对 PresentationCore、PresentationFramework 和 WindowsBase 的引用.不幸的是,这似乎不起作用.

Now I need to use an existing plain Class Library project to host a shared resource dictionary. That means I need to retrofit the Class Library project to support the Component Resource Key markup extension. I have added a Themes folder and a Generic.xaml resource dictionary document to the Class Library project, as well as references to PresentationCore, PresentationFramework, and WindowsBase. Unfortunately, that doesn't seem to do the trick.

所以,这是我的问题:除了上述问题之外,WPF 自定义控件库项目有哪些普通类库项目没有的功能?或者,换句话说,我还可以向我的类库项目中添加什么来使此功能正常工作?谢谢.

So, here is my question: Other than the above, what does a WPF Custom Control Library project have that a plain Class Library project doesn't? Or, to put it another way, what else could I add to my class library project to get this feature working? Thanks.

推荐答案

除了额外的 WPF 引用之外,WPF 自定义控件库模板在 AssemblyInfo 中有一个额外的属性.

Apart from the extra WPF references, the WPF Custom Control Library template has an extra attribute in AssemblyInfo.

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
    //(used if a resource is not found in the page, 
    // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
    //(used if a resource is not found in the page, 
    // app, or any theme specific resource dictionaries)
)]

ThemeInfoAttribute 指定主题词典所在的位置存储在程序集中的类型.

ThemeInfoAttribute specifies the location in which theme dictionaries are stored for types in an assembly.

这篇关于WPF自定义控件库和普通类库的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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