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

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

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



        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 13:24

    Found all answers useful, just wanted to add one more use case.

    In a composite WPF scenario, your user control can make use of resources defined in any other parent window/control (that is going to host this user control) by referring to that resource as DynamicResource.

    As mentioned by others, Staticresource will be looked up at compile time. User controls can not refer to those resources which are defined in hosting/parent control. Though, DynamicResource could be used in this case.

提交回复
热议问题