Skip to content

WinUI Custom Controls \ Resource Dictionaries - Invalid in packed nuget libraries #10794

@ajbadaj

Description

@ajbadaj

Describe the bug

I have an open source library, AJut - which has c# & WPF controls and utilities. I was trying to expand into WinUI3 - and so I made AJut.UX.WinUI3. To test that library, in the same solution, I have a showroom app AJutShowRoomWinUI and that references AJut.UX.WinUI3 via project reference.

The show room works fine! However, when I package up AJut.UX.WinUI3 and push it to nuget, then try it in a sample application, I can see two distinct bad behaviors:

  1. In the test app if I use one of the custom controls, say GeometryButton via: <ajut:GeometryButton Content="A Geometry Button" BackgroundGeometry="M 0,0 20,20 40,0 150,0 150,100 100,90 0,100 Z" TraceThickness="1" Margin="5" Width="350" Height="75"/> - then instead of my custom button visuals, I get a blank nothing. The live visual tree shows: GeometryButton → Grid → TextBlock but doesn't show anything.
  2. If in the test app I try to include the theme colors through something like: <ResourceDictionary Source="ms-appx:///AJut.UX.WinUI3/Resources/DarkThemeColorsBase.xaml"/> - then it crashes saying: "Cannot locate resource from 'ms-appx:///AJut.UX.WinUI3/Resources/DarkThemeColorsBase.xaml'"

I've gone through many iterations trying to fix this including:

  • Turning off "EnableDefaultPageItems and then explicitly calling out all my pages
  • Trying out the settings: DisableEmbeddedXbf (false), GenerateLibraryLayout(true), and IncludePriFilesOutputGroup(true)

Why is this important?

I didn't think making this library would be difficult, and I'm doing it because I'm trying to build a commercial WinUI3 application - and so far this kind of roadblock is giving me a lot of pause.

It should be easy for developers to make control and theming libraries that they share over nuget, and if that basic application of WinUI3 development doesn't work - then it will hamper the ecosystem, as well as push people away from taking it seriously.

Steps to reproduce the bug

  1. Create a WinUI3 library with custom controls (with resource dictionaries for default styles that are included in the library's generic.xaml) and resource dictionaries for reference
  2. Build, pack, and publish that library on Nuget
  3. Create a test WinUI3 executable and pull in that library
  4. Use the custom control
  5. Try and import the theming resource dictionary

Actual behavior

In step 4, the app runs - but the style is missing. In step 5 the app crashes.

Expected behavior

You can use custom controls and import resource dictionaries from packed dotnet WinUi3 libraries and the controls show up with their style.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.8.0: 1.8.250907003

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs to be triaged by the area owners

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions