StaticResource vs DynamicResource

I’ve been focusing a lot (read: “learning”) on WPF lately, and one thing that crops up all the time is StaticResource and DynamicResource. I had tried to infer their usage/differences from the context of where I’d seen them used, but I could never quite get it right. Anyway, I just read a nice definition which makes it all rather clear:

Static resources are resolved at compile time, whereas dynamic resources are resolved at runtime.

Use DynamicResources when the value of the resource could change during the lifetime of the Application.

Use StaticResources when it’s clear that you don’t need your resource re-evaluated when fetching it – static resources perform better than dynamic resources.

Posted in .Net, WPF by Gerrod at June 17th, 2008.
Tags: ,

4 Responses to “StaticResource vs DynamicResource”

  1. lelt lelt tun says:

    Thanks a lot for your explain about StaticResource vs DynamicResource.

  2. Asim Sajjad says:

    Thanks for nice short article , It really help me to distinguish betwee the static and dynamic resource

  3. stu says:

    Are there any performance tests out there between static and dynamic resources? I’d love to see some metrics.

    Many designer problems in VS and blend just go away when I use dynamic resources, but I’m concerned about performance.

  4. Drew says:

    There is a performance penalty with a dynamic resource.
    http://msdn.microsoft.com/en-us/library/bb613559.aspx

    Not sure if anybody has done any real world analysis. Maybe check out Tim Cahill’s WPF Performance blog?

Leave a Reply