tom greene
tom greene

Reputation: 5449

Is there a way to define WPF custom bindings?

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?

Upvotes: 1

Views: 145

Answers (1)

Kris
Kris

Reputation: 7170

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

Upvotes: 5

Related Questions