Bug: Unable to Inherit from MUX WinUI 2.x Controls in C#
See original GitHub issueDescribe 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:
- Using the WUX namespace set a breakpoint on
base.OnApplyTemplate()
. When code is run the breakpoint should be hit: - Change to the MUX namespace for the base control and run again with the same breakpoint:
- The breakpoint in OnApplyTemplate() is never hit and the control template is never applied.
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:
UWP | Win32 |
---|---|
Yes | N/A |
Windows 10 version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
May 2020 Update (19041) | Yes |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Additional context
This is a pretty major roadblock. I need a work-around or fix pretty quickly…
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Integrate WinUI with WPF (Existing as well as new)
But i am unable to access the controls from the Microsoft.UI.XAML. It says doesnt exist. Please advice whether i am trying with the...
Read more >Updates to .NET Core Windows Forms designer in Visual ...
We are happy to announce the new preview version of the .NET Core Windows Forms designer, which is available with the Visual Studio...
Read more >Build XAML controls with C# - Windows apps
This article walks you through creating a templated XAML control for WinUI 3 with C#. Templated controls inherit from Microsoft.UI.Xaml.
Read more >Avalonia textbox textchanged. It looks like it's required for IME ...
I find out OnPointerEnter is a method defined in InputElement(interface) inherited by Control inherited by TextBox, but there's no such a method in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just hit this again and forgot about
DefaultStyleResourceUri
.However, when the platform can’t find the specified style for a control before
OnApplyTemplate
is called, it feels like this should really be throwing an exception with those types of details like “Can’t find resource X from ResourceUri Y” as then it’d be immediately obvious there’s a problem. What it’s trying to look for, and where it’s trying to look (in the example above it’d be the WinUI generic.xaml instead of the Toolkit one as we would have expected).Otherwise, with just a silent eating it, no
OnApplyTemplate
and no rendering of the control, it’s just a black box and takes forever to debug. So many hours some times to realize what’s going on or to find what’s causing an issue.Hit this again, almost forgot about it again…