Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the default style for a type in code behind

In WPF, you can create a Style that acts as the default for a control type in XAML:

<Style TargetType="{x:Type local:MyControl}">
    . . .
</Style>

Then, when WPF goes to display that control, it looks up that Style from the resources based on the its type.

I want to do the equivalent of this in the code-behind of my program. How do I find that Style?

like image 492
Tony Vitabile Avatar asked Feb 27 '13 22:02

Tony Vitabile


1 Answers

You can search for the style in the Application-level resources by using the control type as the key:

Style defaultStyle = Application.Current.TryFindResource(typeof(MyControl)) as Style;
like image 108
ZF. Avatar answered Sep 28 '22 12:09

ZF.