How do I tell a control or block of controls to not inherit any styles and revert back to the defaults?
I need this because I have an overall theme that mostly works, but for one piece really screws up my design.
How do I tell a control or block of controls to not inherit any styles and revert back to the defaults?
I need this because I have an overall theme that mostly works, but for one piece really screws up my design.
This is tricky but you can try this,
<Style x:Key="DefaultButtonStyle"
TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"/>
Make sure this DefaultStyles is added before any of your themes are applied, it should be the first entry in your app resources.
Then you can apply style "DefaultButtonStyle" to any control at runtime to retain its default style.
You could create your own container for the piece of UI in question, and alter InheritanceBehavior
to return SkipAllNow
, or whatever is most appropriate for your situation:
public class NoInheritanceContentControl : ContentControl
{
public MyContainer()
{
this.InheritanceBehavior = InheritanceBehavior.SkipAllNow;
}
}
Then you can just stick NoInheritanceContentControl
in your visual tree and anything inside it won't inherit styles.
HTH,
Kent