Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ThemeInfo属性的作用是什么?_C#_Wpf_Xaml_Themes_Assemblyinfo - Fatal编程技术网

C# ThemeInfo属性的作用是什么?

C# ThemeInfo属性的作用是什么?,c#,wpf,xaml,themes,assemblyinfo,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 reso

每当我创建新的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)
)]

ThemeInfo
属性用于什么?如果删除它,是否会破坏任何内容?

ThemeInfo属性指定自动主题机制应在何处查找主题词典和通用词典。每个选项都可以设置为以下值之一:

  • 无(默认):不查找资源字典
  • SourceAssembly:字典是当前程序集
  • ExternalAssembly:词典位于另一个程序集中,必须命名为
    .dll
    ,其中
    是当前程序集的 名字

如果主题词典为外部程序集中定义的控件指定样式,例如,WPF控件,如
System.Windows.controls.ProgressBar
System.Windows.Button
,然后必须使用
主题词典扩展
将应用程序指定为主题词典的源。

WPF框架在控件库中使用此属性作为将资源应用于控件的方便方法

考虑到Windows可以运行不同的UI主题(Aero就是这样一个例子)。Microsoft提供的WPF控件可根据不同的环境主题更改其外观

如果应用程序需要此行为,则可以在控件库项目的
themes
文件夹中创建不同的主题词典

即使您不需要多主题支持,也可以方便地将资源放在
generic.xaml
文件中,以便程序集中的控件可以访问这些资源。可能您的元素(控件)是在
.cs
文件中定义的,而没有
.xaml
部分类,您需要某个地方来存储它所需的资源,或者(更可能)您有将在同一项目/程序集中的多个WPF元素之间共享的资源


这里所指的属性是用于映射这些资源的元数据。

但这意味着什么?什么是“主题词典”?什么是“通用词典”?它们是干什么用的?它们重要吗?而且,正如我在我的问题中所问的,如果我删除属性,我会破坏任何东西吗?因为我知道如果你将删除,你的控件将不会从generic.xaml中获取主题,它会说在哪里搜索generic themethy you!我一直在疯狂尝试将基于主题的样式应用于外部定义的控件。我不知道主题词典的扩展。一旦我把它加进去,一切终于都起作用了!再次感谢!!所以如果我使用标准的主题控件,比如Button,我不需要这个属性?如果:(a)我是从头开始编写自己的控件,需要在Aero和Luna等中看起来有所不同,或者(b)我的程序集有一个generic.xaml文件,我才需要它?在这两种情况下,默认值都不起作用,我需要该属性?是的,您在这里走的是对的,但是我在谈论您自己的控件时,没有任何“默认”资源。您可能通过“generic.xaml”文件获得的唯一默认值。该词典中的资源被特定主题的资源词典条目覆盖,如果它们存在的话!我得到了一个空白/黑色的窗口,因为我构建了一个自定义的BaseView,然后转移到另一个项目。添加这个修复它!