为什么在XAML中设置依赖项属性时

为什么在XAML中设置依赖项属性时

本文介绍了为什么在XAML中设置依赖项属性时,绕过.NET属性包装器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读亚当·内森(Adam Nathan)的著作 WPF 4 Unleashed,第82页有以下警告:

I am reading Adam Nathan's book "WPF 4 Unleashed" and there is the following warning on page 82:

我的问题是:为什么? WPF调用GetValue()/ SetValue()而不是读取/设置CLR属性包装器的原因是什么?如果原因是读取/设置属性包装器需要反射,那么WPF无论如何在构造对象树时都会使用反射,所以真的值得绕过使用属性包装器并直接调用GetValue()/ SetValue()吗?还是避免反射不是这种行为的主要原因?

My question is: Why? What are the reasons that WPF calls GetValue()/SetValue() instead of reading/setting a CLR property wrapper? If the reason is that reading/setting a property wrapper requires reflection, then WPF uses reflection much when constructing an object tree anyway, so is it really worth it to bypass using property wrappers and call GetValue()/SetValue() directly? Or avoiding Reflection is not the main reason for such a behavior?

UPD。 Clemens很快给出了正确的答案,但是我只想添加一个该MSDN页面上的更多报价(据我了解,StackOverflow倾向于使用引号而不是链接):

UPD. Clemens quickly gave a correct answer, but I would add just one more quote from that MSDN page (as I understand StackOverflow prefers quotes to links):


推荐答案

在:

和:

这篇关于为什么在XAML中设置依赖项属性时,绕过.NET属性包装器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:17