What is the difference between StaticResource and DynamicResource?
Short answer
StaticResource resolves the resource once at load time—efficient but won't reflect later changes. DynamicResource keeps a live link, updating the target if the resource is replaced (e.g., swapping a theme dictionary at runtime).
Advertisement
AModel answer
StaticResource resolves the resource once at load time—efficient but won't reflect later changes. DynamicResource keeps a live link, updating the target if the resource is replaced (e.g., swapping a theme dictionary at runtime). Use DynamicResource only where runtime changes are needed, since it has slight overhead.
<!-- Updates live if 'Primary' is swapped at runtime -->
<Button BackgroundColor="{DynamicResource Primary}" />Real-world example
Theme colors use DynamicResource so switching light/dark at runtime recolors the UI instantly, while static values use StaticResource.
Likely follow-ups
- When must you use DynamicResource? | What's the performance trade-off?
Related topics