Share via


BindingMode Enum

Definition

Specifies the direction of data flow in a binding.

public enum class BindingMode
public enum BindingMode
type BindingMode = 
Public Enum BindingMode
Inheritance
BindingMode

Fields

Name Value Description
Default 0

Uses the default binding mode for the target property.

TwoWay 1

Updates both the target and source when either changes.

OneWay 2

Updates the target when the source changes.

OneWayToSource 3

Updates the source when the target changes.

OneTime 4

Updates the target only once when the binding is created.

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