Inheriting the implicit style not working fine in WinUI 3 for desktop
See original GitHub issueI have a custom control CustomControl1
public class CustomControl1 : Control
{
public CustomControl1()
{
this.DefaultStyleKey = typeof(CustomControl1);
}
}
Whose implicit style is
<Style TargetType="local:CustomControl1">
<Setter Property="Background" Value="Green"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomControl1">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And a second custom control CustomControl2, inheriting CustomControl1
public class CustomControl2 : CustomControl1
{
public CustomControl2()
{
DefaultStyleKey = typeof(CustomControl2);
}
}
whose implicit style only sets the Background
<Style TargetType="local:CustomControl2">
<Setter Property="Background" Value="Red"/>
</Style>
The problem is the “Template” of CustomControl1 is not inherited automatically. Therefore nothing is rendered.
This looks as a bug as the implicit style of CustomControl2 doesn’t override Template, so it should take the parent one.
In case that were intentional, there should be at least a way to base the style on the parent control implicit style, I couldn’t find anything, x:Type doesn’t exist in WinUI. Is there any way round?
Here the repo project App12.zip
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (2 by maintainers)
Top Results From Across the Web
XAML styles - Windows apps
In this article · WinUI and styles · Style basics · Apply an implicit or explicit style · Use based-on styles · Use...
Read more >How to inherit from, or override elements of, the Default ...
I am trying to learn how to use Styles most effectively in WinUI 3 (from WindowsAppSDK 1.1.1) but I'm having difficulty getting simple ......
Read more >Custom Style dynamic Inheritance of theme in UI for WPF
Hi, Telerik! I have created some helper class for setting default theme. In it I applied StyleManager.ApplicationTheme with needed default theme ...
Read more >Implicit and Explicit Styles in XAML - Nick's .NET Travels
By explicitly setting the Style attribute on the Button, the implicit Style is no longer being applied. Luckily, we can create derived styles ......
Read more >Application crashes if appearance properties are set from a ...
I have 2 issues to report. ... a StaticResource and DataGridView's style does not apply appearance properties ... And the resource file:.
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
This is still a big issue. Is there any light in the horizon?
@arivoir Given the current constraint, I think you best bet is to wrap the control instead of inheriting it. If you need those properties/methods, then you will need to use the adapter pattern to adapt one by one.