Custom Control Default Style in Themes/Generic.xaml Not Applied #10196
Unanswered
4broadcast
asked this question in
Q&A
Replies: 1 comment
-
After further investigation, the problem is that the DefaultStyleKey is applied for items that inherit from Control or ContentControl, but not for (some?) subclassed Microsoft controls. My issue is very similar to this closed issue #3499. I have a sample showing that if you subclass a more primitive control, the style is applied from Generic.xaml. But for something like a subclass of TreeVIew, it is not applied. My repo is here https://github.com/4broadcast/CustomControlTest. Am I missing something, or is this a bug? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a fairly large WinUI 3 / c# /WASDK 1.6 app, to which I've just added a new templated/custom control. I have the default style in a Generic.xaml resource dictionary, located in the (~Project)/Themes folder.
When I run my app, the default style is not applied to my control. The only way to get my template applied is to manually add Generic.xaml as a merged dictionary in App.xaml resources.
To restate: If Generic.xaml is manually added as a merged dictionary, the default style is applied. If Generic.xaml is not manually referenced, it is ignored or otherwise not found.
I have created a sample app, and used the sample control from here: https://learn.microsoft.com/en-us/windows/apps/winui/winui3/xaml-templated-controls-csharp-winui-3
The sample works as expected; as long as there's a Themes/Generic.xaml containing a default template, that style is applied. It DOES NOT need to be added as a merged dictionary.
Where should I be looking in my app to troubleshoot why Themes/Generic.xaml is not getting picked up? I've tried comparing the sample and real app configurations, and I see no material difference.
Thanks-
jerry
Beta Was this translation helpful? Give feedback.
All reactions