【发布时间】:2010-08-17 17:00:05
【问题描述】:
我刚刚回答了一个问题over here,我说两者在功能上没有区别
{Binding TargetProperty}
和
{Binding Path=TargetProperty}
而且,据我所知,我所写的内容基本上是正确的。然而,一个人将使用构造函数,另一个人设置属性的想法让我觉得可能有所不同,所以我打开了反射器并看了一下。
构造函数中包含以下代码:
public Binding(string path)
{
this._source = UnsetSource;
if (path != null)
{
if (Dispatcher.CurrentDispatcher == null)
{
throw new InvalidOperationException();
}
this._ppath = new PropertyPath(path, new object[0]);
this._attachedPropertiesInPath = -1;
}
}
路径属性是这样的:
public PropertyPath Path
{
get
{
return this._ppath;
}
set
{
base.CheckSealed();
this._ppath = value;
this._attachedPropertiesInPath = -1;
base.ClearFlag(BindingBase.BindingFlags.PathGeneratedInternally);
}
}
因此,当您通过属性设置路径时,PathGeneratedInternally 标志被清除。现在,这个标志并没有直接公开暴露在任何地方,但它似乎确实在一些地方被使用:
internal void UsePath(PropertyPath path)
{
this._ppath = path;
base.SetFlag(BindingBase.BindingFlags.PathGeneratedInternally);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializePath()
{
return ((this._ppath != null) && !base.TestFlag(BindingBase.BindingFlags.PathGeneratedInternally));
}
我确信这一切都无关紧要,但是有没有人知道这个标志的含义以及为什么它可能会根据您声明绑定的方式而有所不同?
【问题讨论】: