viking_grll
viking_grll

Reputation: 131

What's the equivalent of FindResource for finding a resource by control type?

I want to do FindResource("{x:Type TextBox}") or FindResource(GetType(TextBox)) and get a Style object back?

Kind regards,

Upvotes: 0

Views: 394

Answers (1)

mm8
mm8

Reputation: 169300

This will find an implicit Style (without an x:Key):

Style style = FindResource(typeof(Button)) as Style;

...that is defined in your XAML markup like this:

<Style TargetType="Button">
    <Setter Property="FontSize" Value="40" />
</Style>

In VB.NET the corresponding code would be:

Dim style As Style = TryCast(FindResource(GetType(Button)), Style)

Upvotes: 1

Related Questions