Oliver
Oliver

Reputation: 11617

Are Brushes defined in WPF Style Setters instantiated every time the style is used?

Please consider the following xaml fragment:

<Style x:Key="CustomBorderStyle" TargetType="Border">
    <Setter Property="Background">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                <GradientStop Color="#CCC" Offset="0.45"/>
                <GradientStop Color="#444" Offset="0.8"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
</Style>

Suppose the style is defined in an application-level resource dictionary. When a control references the style, does WPF instantiate a new instance of the LinearGradientBrush class every time? Or is there a single shared instance of LinearGradientBrush that is used?

I would like to know if it would be more efficient to define the LinearGradientBrush elsewhere, and then reference it in the Style as static resource.

Upvotes: 0

Views: 50

Answers (1)

Joey
Joey

Reputation: 354744

There is only one instance of that style and of its constituent objects.

Upvotes: 1

Related Questions