Export (0) Print
Expand All

Binding.Mode Property

Gets or sets a value that indicates the direction of the data flow in the binding.

Namespace: System.Windows.Data
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

Public Property Mode As BindingMode
Dim instance As Binding
Dim value As BindingMode

value = instance.Mode

instance.Mode = value
/** @property */
public BindingMode get_Mode ()

/** @property */
public void set_Mode (BindingMode value)

public function get Mode () : BindingMode

public function set Mode (value : BindingMode)

<object Mode="BindingMode" .../>

Property Value

One of the BindingMode values. The default value is Default, which returns the default binding mode value of the target dependency property. However, the default value varies for each dependency property. In general, user-editable control properties, such as those of text boxes and check boxes, default to two-way bindings, whereas most other properties default to one-way bindings. A programmatic way to determine whether a dependency property binds one-way or two-way by default is to get the property metadata of the property using GetMetadata and then check the Boolean value of the BindsTwoWayByDefault property.

To support OneWay and TwoWay bindings, the underlying data must implement INotifyPropertyChanged. For details, see Implement Property Change Notification.

For TwoWay or OneWayToSource bindings, you can control the target-to-source updates by setting the UpdateSourceTrigger property. For more information, see UpdateSourceTrigger.

For more information on the different binding modes, see Data Binding Overview.

This example shows how to specify whether the binding updates only the binding target (target) property, the binding source (source) property, or both the target property and the source property.

You use the Mode property to specify the direction of the binding. The following enumeration list shows the available options for binding updates:

  • TwoWay updates the target property or the property whenever either the target property or the source property changes.

  • OneWay updates the target property only when the source property changes.

  • OneTime updates the target property only when the application starts or when the DataContext undergoes a change.

  • OneWayToSource updates the source property when the target property changes.

  • Default causes the default Mode value of target property to be used.

For more information, see the BindingMode enumeration.

The following example shows how to set the Mode property. For the complete sample, see Binding Modes Sample.

<TextBlock Name="IncomeText" Grid.Row="0" Grid.Column="1"
  Text="{Binding Path=TotalIncome, Mode=OneTime}"/>

To detect source changes (applicable to OneWay and TwoWay bindings), the source must implement a suitable property change notification mechanism such as INotifyPropertyChanged. See Implement Property Change Notification for an example of an INotifyPropertyChanged implementation.

For TwoWay or OneWayToSource bindings, you can control the timing of the source updates by setting the UpdateSourceTrigger property. See UpdateSourceTrigger for more information.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2014 Microsoft