question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Unable to Inherit from MUX WinUI 2.x Controls in C#

See original GitHub issue

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

  1. Using the WUX namespace set a breakpoint on base.OnApplyTemplate(). When code is run the breakpoint should be hit: image
  2. Change to the MUX namespace for the base control and run again with the same breakpoint: image
  3. 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: image

Using MUX no template is applied: image

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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
michael-hawkercommented, Jul 23, 2021

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.

1reaction
michael-hawkercommented, Jun 7, 2022

Hit this again, almost forgot about it again…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found