CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.85k stars 1.37k forks source link

[Investigation] Are our named Resources Exposed to Applications Properly? #3603

Open michael-hawker opened 3 years ago

michael-hawker commented 3 years ago

See start of discussion on this thread here: https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3556#issuecomment-726656619

Describe the bug

When a developer uses the Toolkit they should have access to the style/resources we expose in order to use them as a basis for modifications. On the discussion above, it's unclear if that's happening properly or not...

Steps to Reproduce

Steps to reproduce the behavior:

  1. Start a new project
  2. Include the Controls package
  3. Go to MainPage
  4. Add <Page.Resources> and try and create a new style based on a DefaultTokenizingTextBoxStyle
  5. Try to use a new style on the control
  6. Compile... does this work?

Expected behavior

It should work...

Related to #3602

alvinashcraft commented 3 years ago

So, when I try this, IntelliSense tells me that the DefaultTokenizingTextBoxStyle is not found. It compiles fine, but I get a Xaml error at runtime during app startup.

michael-hawker commented 3 years ago

Thanks for taking a look @alvinashcraft so seems like we may be missing something to expose these. I wonder if this works differently in UWP and that's why WinUI forces the add to App.xaml?

@ranjeshj do you know who we'd talk to about how this system works and if this is expected or not?

yoshiask commented 3 years ago

I wonder if this works differently in UWP and that's why WinUI forces the add to App.xaml?

I'm pretty sure this is correct, I vaguely remember someone from the WinUI team mentioning this limitation. Might have been an early community call or something.

Are there any updates on this investigation? Is the WCT going to do the same as WinUI?

michael-hawker commented 3 years ago

I think this is a platform limitation and related to this issue here maybe? https://github.com/microsoft/microsoft-ui-xaml/issues/3502

sylveon commented 3 years ago

Accessing named resources defined in Themes\Generic.xaml doesn't even work from within the same project, so it seems like an intentional design choice that the resources in there aren't added to the application's resources by default.

marcelwgn commented 3 years ago

@sylveon Is 100% correct, this seems to be by design. Styles inside Themes\Generic.xaml files will be used to lookup the default style, however resource wise, you can't access them. Only way to access them is by manually adding them to the resources dictionary (e.g. through merged dictionaries). This is also what WinUI does. Not that manually referencing the resources will also override existing resource if they have also been defined in the WCT (as is the case with a few resources).