Differences between WPF Custom Control Library and plain Class Library?

后端 未结 3 1758
Happy的楠姐
Happy的楠姐 2021-01-13 02:11

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. A

相关标签:
3条回答
  • 2021-01-13 02:30

    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 specifies the location in which theme dictionaries are stored for types in an assembly.

    0 讨论(0)
  • 2021-01-13 02:31

    Another difference is in the .csproj File:

    In class Library the Tag is missing:

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

    After adding it to the first PropertyGroup, the add menu of the project shows now the typical WPF files.

    0 讨论(0)
  • 2021-01-13 02:38

    Cameron MacFarland's answer was spot on. I have now tested it, and it works.

    Here is the solution: Add the DLL refs and the Themes/generic.xaml file to the plain Class Library project. Then, open AssemblyInfo.cs and add the following code at the end of the file:

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

    Recompile, and the Component Resource Key markup extension should work.

    0 讨论(0)
提交回复
热议问题