WPF自定义控件库和WPF类库有什么不同 [英] What is the difference between wpf custom control library and wpf class Library

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

问题描述

WPF自定义控件库和WPF类库的基本区别是什么?我想了解一下它们在DLL和体系结构方面的不同。因为自定义控件本身是一个类,WPF类库也包含类。但自定义控件类在WPF类库中不起作用。

推荐答案

您可以将WPF自定义控件库视为具有更多配置的简单类库:

ThemeInfo程序集属性:

[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)

)]

上述属性指定在何处查找控件的默认样式/模板。您可以从上面的注释中了解ResourceDictionaryLocation.SourceAssembly所做的事情,SourceAssembly中搜索Resources的默认位置是在添加新的WPF自定义控件库时默认创建的特殊路径Themes/Generic.xaml

您可以手动添加这些控件,并将类库转换为WPF自定义控件库。

如果没有ThemeInfo属性,则仅在应用程序资源词典中搜索默认样式/模板,如果没有,则会出现错误。这就是CustomControls最常不适用于类库的原因。

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

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