【XAML】StaticResource 与 DynamicResource 的区别

StaticResource  是在加载 XAML 的时候赋值给属性的,发生在程序真正运行之前,而且只会被赋值一次,之后,任何对资源的更改将被忽略。简言之:值只被检索一次然后再整个生命周期中使用。

DynamicResource 是在加载的时候给属性赋值一个表达式对象,但不会真正地去查找对应的资源,直到属性被真正的使用的时候才会去查找。这种特性将资源的查找推迟到了运行过程中真正需要的时刻。一个很好的例子就是事先引用一个在之后才会在XAML中定义的资源,另一个例子就是引用一个只有在运行时才会存在的资源。简言之:值在每次使用的时候都会被重新检索。

 
原文如下:
A StaticResource will be resolved and assigned to the property during the loading of the XAML which occurs before the application is actually run. It will only be assigned once and any changes to resource dictionary ignored.

A DynamicResource assigns an Expression object to the property during loading but does not actually lookup the resource until runtime when the Expression object is asked for the value. This defers looking up the resource until it is needed at runtime. A good example would be a forward reference to a resource defined later on in the XAML. Another example is a resource that will not even exist until runtime. It will update the target if the source resource dictionary is changed.

 

原帖: http://stackoverflow.com/questions/200839/whats-the-difference-between-staticresource-and-dynamicresource-in-wpf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值