Joe*_*ite 30 c# wpf xaml themes assemblyinfo
每当我创建新的WPF应用程序或WPF用户控件库时,该AssemblyInfo.cs
文件都包含以下属性:
[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)
)]
Run Code Online (Sandbox Code Playgroud)
这个ThemeInfo
属性是什么?如果我删除它会破坏任何东西吗?
Ars*_*yan 17
ThemeInfo属性指定自动主题机制应该在哪里查找主题词典和通用词典.每个选项都可以设置为以下值之一:
<AssemblyName>.<ThemeName>.dll
,其中<AssemblyName>
是当前程序集的名称.如果主题词典为外部程序集中定义的控件指定样式,例如,WPF控件如System.Windows.Controls.ProgressBar
和System.Windows.Button
,则必须使用它ThemeDictionaryExtension
来指定应用程序作为主题词典的源.
WPF框架在控件库中使用此属性作为将资源应用于控件的便捷方式.
考虑到Windows可以使用不同的UI主题运行(Aero就是这样一个例子).Microsoft提供的WPF控件会针对不同的环境主题更改其外观.
如果您的应用程序需要此行为,则可以在themes
控件库项目的文件夹中创建不同的主题词典.
即使您不需要多主题支持,也可以方便地将资源放入generic.xaml
文件中,以便程序集中的控件可以访问它们.也许您的元素(控件)是在.cs
没有.xaml
分部类的文件中定义的,并且您需要在某处存储它所需的资源,或者(更有可能)您拥有将在同一项目/程序集中的许多WPF元素之间共享的资源.
您在此处引用的属性是用于映射这些资源的元数据.