Style selecting a user control that inherits from a base control
See original GitHub issueI want to apply a style to a custom usercontrol that inherits from Panel like this:
public class CheckBoxControlledPanel : Panel, IStyleable
{
Type IStyleable.StyleKey => typeof(Panel);
<Style Selector="Panel.WriteReq">
<Setter Property="IsEnabled" Value="..."/>
</Style>
<uc:CheckBoxControlledPanel Classes="WriteReq">
But my Style does not seem to apply. Is this simply not possible or am I doing something wrong?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Style inherited control like base control
In WPF/C# I want to define a new class inheriting from an existing control, but which uses the style of the base control....
Read more >WPF UserControl and inheritance (how to?)
Implicitly a WPF UserControl inherits from base class UserControl. In C# you cannot inherit from 2 classes like in C++. For Inheritance you...
Read more >Cascade, specificity, and inheritance - Learn web development
Controlling inheritance · inherit. Sets the property value applied to a selected element to be the same as that of its parent element....
Read more >Why I cannot inherit a usercontrol from templatedcontrol?
Templated control has no Content property. I think you need to annotate your Content-property with the [Content] attribute for the XAML-Compiler to understand....
Read more >Difference between a UserControl and a CustomControl
Either you can create an User control inheriting from UserControl and adding a XAML for your control or use CustomControl to write yourself....
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 Free
Top 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
I know - it's not possible to select a usercontrol with a style
yes it’s possible…
add an xmlns statement for the namespace where the control lives.
add a style selector like:
ns|MyUserControl
Thanks! I didn’t know about
SetValue
. I see that this gives priority to the Style binding. Is there a way for both the Style binding and the code-behindSetValue
to work or is it not possible for both to compete for the same binding? I’d like the end result to be Style takes highest priority but if Style IsEnabled istrue
, then theSetValue
takes second priority. I don’t see acontrol.GetValue(IsEnabledProperty, BindingPriority.Style);
method that would allow me to check to see if the current value is coming from the Style or not.Maybe my idea ofI think this isn’t possible through the style because - as far as I know - it’s not possible to select a usercontrol with a style (andIsEnabledOverride
should be the way to go?IsEnabledOverride
isn’t present onPanel
). Am I wrong?