views:

41

answers:

1

WPF already defines Binding and TemplateBinding. Is there a way to define my own custom binding type.

For example, could I declare a "SelfBinding" where RelativeSource == RelativeSource.Self?

+3  A: 

Yes, Binding and TemplateBinding are known as markup extensions and you can create your own. Also see here for implementation details.

Edit:You can just inherit from binding making it very simple.

public class SelfBinding : Binding
{
    public SelfBinding(string path) : base(path)
    {
        RelativeSource = new RelativeSource(RelativeSourceMode.Self);
    }
}
Kris
There ought to be some kind of zen-poet award for giving an answer which is perfect, includes the authoritative link *and* all goes on one line.
Will Dean
Added a different link and ruined its zen-ness.
Kris