siva
siva

Reputation: 1265

Regarding usage of binding: WPF Solid Color Brushes

I have a UserControl that defines a Grid Like this :

<Grid ClipToBounds="True"
      x:Name="GHeader"
      Grid.Row="0"
      Grid.Column="0"
      Background="{DynamicResource BrushRoomHeaderBackground}"
      >

The following styles are defined in ResourceDictionary which are loaded at the start:

<SolidColorBrush x:Key="BrushRoomHeaderBackground" 
                 Color="{DynamicResource ColorPassive}"
                 /> 

<Color x:Key="ColorPassive">#FF9499C0</Color>

Should DynamicResource binding be used or StaticResource ? Could there be any memory leak here ?

Upvotes: 0

Views: 173

Answers (1)

Ouarzy
Ouarzy

Reputation: 3043

As explained Manish you should have a look on his link to have a better understanding of the difference between Static and Dynamic ressource.

The short story is:

  • StaticResource are resolved during the loading of the XAML (only once even before application running)
  • DynamicResource are resolved at runtime, and will be updated if the source dictionnary changed

So for you the question is: did you plan to update your dictionnary at runtime, or at least is your ressource defined after the grid declaration? If not, prefer StaticResource for clarity and performance.

Upvotes: 1

Related Questions