代码之家  ›  专栏  ›  技术社区  ›  David Veeneman

wpf自定义控件库与普通类库的区别?

  •  5
  • David Veeneman  · 技术社区  · 15 年前

    几个月前我发了一个关于 sharing resource dictionaries across assemblies . 事实证明,您可以使用组件资源键标记扩展来实现这一点。当时,我只能让它与wpf自定义控件项目一起工作,而不能与普通类库项目一起工作。

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

    所以,这里是我的问题:除了上面提到的,一个wpf自定义控件库项目有什么普通类库项目没有的?或者,换一种说法,我还能在类库项目中添加什么来让这个特性工作呢?谢谢。

    3 回复  |  直到 13 年前
        1
  •  6
  •   Cameron MacFarland    15 年前

    除了额外的wpf引用之外,wpf自定义控件库模板在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 指定为程序集中的类型存储主题词典的位置。

        2
  •  2
  •   Markus k    13 年前

    另一个区别是.csproj文件:

    类库中缺少标记:

    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    

    将其添加到第一个propertygroup之后,项目的add菜单现在显示典型的wpf文件。

        3
  •  1
  •   David Veeneman    15 年前

    卡梅伦·麦克法兰的回答很准确。我现在已经测试过了,而且有效。

    解决方案是:将dll refs和themes/generic.xaml文件添加到普通类库项目中。然后,打开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)
    )]
    

    重新编译,组件资源键标记扩展应该可以工作。