-
Notifications
You must be signed in to change notification settings - Fork 710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Unable to Inherit from MUX WinUI 2.x Controls in C# #3502
Comments
Seems I missed a bug report as well: #3499 |
@robloo can you try adding this in your control as a workaround? this.DefaultStyleResourceUri = new System.Uri("ms-appx:///Themes/Generic.xaml"); |
@stevenbrix Thanks for that trick, I never knew that property existed allowing you to set the default style location. Always relied on the magic generic.xaml being found behind the scenes. Regardless, this did "fix" the issue or at least provide a work-around. I guess this is one of those things that will just disappear with WinUI 3.0 so the work-around is probably enough for now. Edit: This might need to be looked at in more detail from a controls library perspective. It should probably automatically resolve correctly by itself somehow even when using a controls library NuGet. |
@robloo, yeah this was something that I just came across a well. I agree, I like this better than the magical generic.xaml. I don't think WinUI3 will fix this issue. The WCT had the exact same problem with WinUI3.
I agree 100%. I think there are ways we could have our default item templates set this. @MikeHillberg, do you have any thoughts? |
Any updates on this issue? Is this an inherent limitation in UWP compared to how this worked in WPF? Do we basically have to hard-code and merge the resource from the assembly into the app's resource dictionary? (See our discussion in the Toolkit here: CommunityToolkit/WindowsCommunityToolkit#3603) |
Any updates on this? We started to get this on our TabbedCommandBar, so maybe we'll need to update every control on the toolkit. This will be a big hassle for any library porting to WinUI3, so we would appreciate a fix. |
For the Windows Community Toolkit ColorPicker I also had to add the work around. https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/4010/files |
Just hit this again and forgot about However, when the platform can't find the specified style for a control before Otherwise, with just a silent eating it, no |
…s. WinUI See microsoft/microsoft-ui-xaml#3502 Also update TabbedCommandBarItem DataTemplate to use MUX version of NavigationViewItem
X-Ref related discussion in #5525 |
Hit this again, almost forgot about it again... |
Added workaround for DefaultStyleResourceUri - see microsoft/microsoft-ui-xaml#3502 Removed contract7Present from Style (our min target anyway) - see microsoft/microsoft-ui-xaml#2556 Tested on UWP, WinUI 3, and WASM!
Added workaround for DefaultStyleResourceUri - see microsoft/microsoft-ui-xaml#3502 Removed contract7Present from Style (our min target anyway) - see microsoft/microsoft-ui-xaml#2556 Tested on UWP, WinUI 3, and WASM!
Did this get addressed in WinUI 3? Seems pretty fundamental of an issue... |
Looks like this same bug exists in WinUI 3. Repro project |
Describe the bug
Unable to create new controls inheriting from a MUX WinUI 2.x base control. The control template will never be applied.
Steps to reproduce the bug
Using the attached repro project below:
InheritTest.zip
base.OnApplyTemplate()
. When code is run the breakpoint should be hit:Note that if you change the
DefaultStyleKey = typeof(ColorPicker)
(the base type) that will work.Expected behavior
It should be possible to inherit from a MUX WinUI 2.x base control and have the new control template applied.
Screenshots
Using WUX the template is correctly applied:

Using MUX no template is applied:

Also see above.
Version Info
NuGet package version:
Microsoft.UI.Xaml 2.4.3
Windows app type:
Additional context
This is a pretty major roadblock. I need a work-around or fix pretty quickly...
The text was updated successfully, but these errors were encountered: