tags:

views:

17

answers:

0

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

 {Binding TargetProperty}

and

 {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.

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

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?