Xamarin.Forms.BindingMode Enumeration
The direction of changes propagation for bindings.

Syntax

public enum BindingMode

Remarks

The following examples shows some BindingMode use cases.

C# Example

public class PersonViewModel
{
  public string Name { get; set; }
  public string Company { get; set; }
}

Label label;
PersonViewModel viewmodel;

//BindingMode.OneWay
label = new Label ();
label.BindingContext = viewmodel = new PersonViewModel ();
label.SetBinding<PersonViewModel> (Label.TextProperty, vm => vm.Name, mode: BindingMode.OneWay);

viewmodel.Name = "John Doe";
Debug.WriteLine (label.Text); //prints "John Doe"
label.Text = "Foo";
Debug.WriteLine (viewmodel.Name); //prints "John Doe"


//BindingMode.TwoWay
label = new Label ();
label.BindingContext = viewmodel = new PersonViewModel ();
label.SetBinding<PersonViewModel> (Label.TextProperty, vm => vm.Name, mode: BindingMode.TwoWay);

viewmodel.Name = "John Doe";
Debug.WriteLine (label.Text); //prints "John Doe"
label.Text = "Foo";
Debug.WriteLine (viewmodel.Name); //prints "Foo"


//BindingMode.OneWayToSource
label = new Label ();
label.BindingContext = viewmodel = new PersonViewModel ();
label.SetBinding<PersonViewModel> (Label.TextProperty, vm => vm.Name, mode: BindingMode.OneWayToSource);

viewmodel.Name = "John Doe";
Debug.WriteLine (label.Text); //prints ""
label.Text = "Foo";
Debug.WriteLine (viewmodel.Name); //prints "Foo"
    

Members

Member NameDescription
DefaultWhen used in Bindings, indicates that the Binding should use the BindableProperty.DefaultBindingMode. When used in BindableProperty declaration, defaults to BindingMode.OneWay.
OneWayIndicates that the binding should only propagates changes from source (usually the View Model) to target (the BindableObject). This is the default mode for most BindableProperty values.
OneWayToSourceIndicates that the binding should only propagates changes from target (the BindableObject) to source (usually the View Model). This is mainly used for read-only BindableProperty values.
TwoWayIndicates that the binding should propagates changes from source (usually the View Model) to target (the BindableObject) in both directions.

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0