0

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 ?

slugster
  • 49,403
  • 14
  • 95
  • 145
siva
  • 1,135
  • 4
  • 17
  • 25
  • See this http://stackoverflow.com/questions/200839/whats-the-difference-between-staticresource-and-dynamicresource-in-wpf – Manish Feb 22 '13 at 07:01

1 Answers1

1

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.

Ouarzy
  • 3,015
  • 1
  • 16
  • 19
  • The solidcolorbrush and the Color in the resourcedictionary are not changed later in the code. they remain as defined. – siva Feb 22 '13 at 08:03