Difference Between Static Resource and Dynamic Resource in WPF

As we already know that in WPF we have two types of Resources. They are Static Resources , and Dynamic Resources

Now let us check out how they are different from each other.



Static Resources Dynamic Resources
Static Resources are the resources that are defined by using StaticResource Markup Extension. The value of these resources are resolved at compile time or before the application runs. This is onetime lookup. Dynamic Resources are those which are defined by using DynamicResource Markup Extension. Value of these resources are resolved at runtime.
It uses the same value throughout the entire lifetime of the application. The value is reevaluated everytime when user demands.
It does not re-evaluate on page reload Re-evaluates everytime page reloads/refresh
Performance wise it is better than Dynamic Resource Use Dynamic Resources only when your application really need it.
Syntax:
< Window.Resources>
< SolidColorBrush x:Key=”brush” Color=”Yellow” />
</Window.Resources>
<TextBlock Text=”StaticResource” Background=”{StaticResource brush}” />
Syntax:
< Window.Resources>
< SolidColorBrush x:Key=”brush” Color=”Yellow” />
</Window.Resources>
<TextBlock Text=”DynamicResource” Background=”{DynamicResource brush}” />