Table of Contents

Bindable

  • IBindingsOwner - a common contract for everyone who wants to use bindings (and tasty extensions for them).
  • IBindable - a contract for each Bindable View that provides a mechanism to control DataContext.
  • DataContext - data context for an element when it participates in data binding.

Data context is a concept that allows elements to inherit information from their parent elements about the data source that is used for binding, as well as other characteristics of the binding, such as the path.

Each Bindable* view must provide a contract to add bindings safely, such as SetBinding() method.

// TODO:

Create custom View contains Bindings

Need to implement IBindable interface.

Basic:

public class CustomView : AnyPlatformUIObject, IBindable
{
    public CustomView()
    {
        Bindings = new List<Binding>();
    }

    public object DataContext { get; set; }

    public List<Binding> Bindings { get; }

    public virtual void SetBindings()
    {
        // set your bindings here
    }
}

Add ViewModel property for typed DataContext:

protected TViewModel ViewModel => (TViewModel) DataContext;

Can be setup:

var view = new CustomView<My>();

Add using: using Softeq.XToolkit.Bindings.Extensions;

Use extention methods:

view.SetDataContext(default(TViewModel));