WPFwiki, wpf, wiki, .net 3.0, windows presentation foundation, FAQ, free resources, solution, development, microsoft Home of the world's largest WPF FAQ
Edit

Category

Resources

Edit

Question

What is the difference between {StaticResource} and {DynamicResource}?

Edit

Answer

Both markup extensions allow you to reference a Resource by its key.

A StaticResource reference is evaluated once, at the time that the XAML is loaded. This means that if something changes in the Resource being referenced, those changes will not be propagated to the property that is referencing that resource.

A DynamicResource reference is evaluated every time the property that is referencing that resource is evaluated.

Typically, {DynamicResource} is used to reference system theme properties exposed by SystemColors, SystemFonts or SystemParameters. Since these values can change at any time during the lifespan of an application, and since these changes should be reflected in the running application, using {DynamicResource} to reference them will take care of automatically updating the UI when the referenced theme properties change.

Edit

Keywords

staticresource, dynamicresource, resource reference

All content is Copyright ©2007 Xceed Software Inc. unless otherwise indicated. See the Terms of Service. Contributors must read and agree to the Contribution Policy. WPFwiki is brought to you by Xceed, makers of the powerful yet free Xceed DataGrid for WPF.