10

Is there any example which can clearly state the difference between Static and dynamic resource. I know the basic difference that Static is loaded once and gets binded at start while dynamic is loaded at run time and rebinded every time the control reloads.

Thanks in advance

Ankit
  • 6,388
  • 8
  • 54
  • 79

2 Answers2

18

If the Desktop Color is changed while the element’s application is running, the element keeps its original color:

<Button>
  <Button.Background>
    <SolidColorBrush Color="{StaticResource {x:Static SystemColors.DesktopColorKey}}" />
  </Button.Background>
  Hello
</Button>

On the other hand, if the element’s color is set using a DynamicResource, it changes when the Desktop Color changes:

 <Button>
      <Button.Background>
        <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.DesktopColorKey}}" />
      </Button.Background>
      Hello
    </Button>
pchajer
  • 1,584
  • 2
  • 13
  • 25
3

A comprehensive resource is available in So itself.Check

What's the difference between StaticResource and DynamicResource in WPF?

Also go through

http://msdn.microsoft.com/en-us/library/ms750613.aspx

http://dedjo.blogspot.com/2007/05/staticresource-dynamicresource-xstatic.html

Community
  • 1
  • 1
biju
  • 17,554
  • 10
  • 59
  • 95