What's the difference between StaticResource and DynamicResource in WPF?

前端 未结 8 2137
长发绾君心
长发绾君心 2020-11-22 12:33

When using resources such as brushes, templates and styles in WPF, they can be specified either as StaticResources



        
8条回答
  •  野性不改
    2020-11-22 13:19

    Dynamic resources can only be used when property being set is on object which is derived from dependency object or freezable where as static resources can be used anywhere. You can abstract away entire control using static resources.

    Static resources are used under following circumstances:

    1. When reaction resource changes at runtime is not required.
    2. If you need a good performance with lots of resources.
    3. While referencing resources within the same dictionary.

    Dynamic resources:

    1. Value of property or style setter theme is not known until runtime
      • This include system, aplication, theme based settings
      • This also includes forward references.
    2. Referencing large resources that may not load when page, windows, usercontrol loads.
    3. Referencing theme styles in a custom control.

提交回复
热议问题