Share via


BindingMode Enum

Definition

The direction of changes propagation for bindings.

public enum BindingMode
type BindingMode = 
Inheritance
System.Enum
BindingMode

Fields

Name Value Description
Default 0

When used in Bindings, indicates that the Binding should use the DefaultBindingMode. When used in BindableProperty declaration, defaults to BindingMode.OneWay.

TwoWay 1

Indicates that the binding should propagates changes from source (usually the View Model) to target (the BindableObject) in both directions.

OneWay 2

Indicates that the binding should only propagate changes from source (usually the View Model) to target (the BindableObject). This is the default mode for most BindableProperty values.

OneWayToSource 3

Indicates that the binding should only propagate changes from target (the BindableObject) to source (usually the View Model). This is mainly used for read-only BindableProperty values.

OneTime 4

Indicates that the binding will be applied only when the binding context changes and the value will not be monitored for changes with INotifyPropertyChanged.

Remarks

The following examples shows some BindingMode use cases.

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 ""
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"

Applies to