EditCategory
Resources
EditQuestion
What is the difference between {StaticResource} and {DynamicResource}?
EditAnswer
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.
EditKeywords
staticresource, dynamicresource, resource reference