什么是PathGeneratedInternally标志WPF的约束力呢? [英] What does the PathGeneratedInternally flag do in a WPF binding?

查看:89
本文介绍了什么是PathGeneratedInternally标志WPF的约束力呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚回答的问题<一href=\"http://stackoverflow.com/questions/3504480/when-to-use-path-in-wpf-binding/3504511#3504511\">over这里,我说没有。

I've just answered a question over here where I said that there is no functional difference between

 {Binding TargetProperty}

 {Binding Path=TargetProperty}

和,据我所知我自己编写基本上是正确的。不过这个想法,一个将使用构造函数和其他套物业让我以为有可以的是有区别的,所以我掀起开放反射器和一看。

and, as far as I'm aware what I have written is fundamentally correct. However the idea that one will use the constructor and the other sets the property got me thinking that there could be a difference, so I whipped open reflector and had a look.

构造中有以下code:

The constructor has the following code in it:

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;
    }
}

路径属性是这样的:

The path property is this:

public PropertyPath Path
{
    get
    {
        return this._ppath;
    }
    set
    {
        base.CheckSealed();
        this._ppath = value;
        this._attachedPropertiesInPath = -1;
        base.ClearFlag(BindingBase.BindingFlags.PathGeneratedInternally);
    }
}

所以,当你通过设置属性的PathGeneratedInternally标志被清除的路径。现在,这个标志不露任何地方直接公开,但它似乎在几个地方使用:

So when you set the path through the property the PathGeneratedInternally flag is cleared. Now, this flag isn't exposed anywhere publicly directly, but it does seem to be used in a few places:

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));
}

我敢肯定,这一切都相当微不足道的,但没有人在那里知道这是什么标志的手段和为什么它取决于你如何申报结合也许有什么不同?

I'm sure it's all fairly inconsequential, but does anyone out there know what this flag means and why it maybe different depending on how you declare the binding?

推荐答案

关键是要看看那里的UsePath方法是从引用。默认情况下该标志不会被设置,因此清除它基本上是一个无操作。没有理由要清除它在构造函数中,因为你知道它没有在这种情况下被设置(因为该对象是否仍然正在建设)。

The key is to see where the UsePath method is referenced from. By default the flag won't be set, so clearing it is basically a no-op. There is no reason to clear it in the constructor, because you know it hasn't been set in that case (because the object is still being constructed).

该UsePath只调用了在一个地方,这就是ClrBindingWorker构造函数。如果你在那里看,你会看到他们自动创建一个空白或空的路径,并传递到UsePath。

The UsePath method is only called in one location and that's the ClrBindingWorker constructor. If you look in there you will see they automatically create a "blank" or "empty" path and pass that to UsePath.

我怀疑他们这样做,所以在内部使用时的路径是有效的,即使它只是指具有约束力源(这是在没有给出路径的默认行为)。如果以后设置绑定Path属性,指示自动生成的路径的标志必须清零。

I suspect they do this so the Path is "valid" when used internally, even if it just refers to the binding source (which is the default behavior when no path is given). If you later set the Path property on the Binding, the flag that indicates the Path was automatically generated must be cleared.

这篇关于什么是PathGeneratedInternally标志WPF的约束力呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆