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.

Style selecting a user control that inherits from a base control

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danwalmsleycommented, Dec 16, 2020

I know - it's not possible to select a usercontrol with a style

yes it’s possible…

  1. add an xmlns statement for the namespace where the control lives.

  2. add a style selector like: ns|MyUserControl

0reactions
derekantricancommented, Dec 16, 2020

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-behind SetValue 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 is true, then the SetValue takes second priority. I don’t see a control.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 of IsEnabledOverride should be the way to go? I 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 (and IsEnabledOverride isn’t present on Panel). Am I wrong?

Read more comments on GitHub >

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

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