如何:指定绑定的方向How to: Specify the direction of the binding

本示例演示如何指定绑定是仅更新绑定目标(目标)属性或绑定源(源)属性,还是同时更新目标属性和源属性。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.

示例Example

使用 Binding.Mode 属性指定绑定的方向。You use the Binding.Mode property to specify the direction of the binding. 下面是绑定更新的可用选项:The following are the available options for binding updates:

有关详细信息,请参见 BindingMode 枚举。For more information, see the BindingMode enumeration.

下面的示例演示如何设置 Mode 属性。The following example shows how to set the Mode property.

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

若要检测源更改(适用于 OneWayTwoWay 绑定),源必须实现适当的属性更改通知机制(如 INotifyPropertyChanged)。To detect source changes (applicable to OneWay and TwoWay bindings), the source must implement a suitable property change notification mechanism such as INotifyPropertyChanged. 有关 INotifyPropertyChanged 实现的示例,请参阅实现属性更改通知See Implement Property Change Notification for an example of an INotifyPropertyChanged implementation.

对于 TwoWayOneWayToSource 绑定,可以通过设置 UpdateSourceTrigger 属性来控制源更新的时间。For TwoWay or OneWayToSource bindings, you can control the timing of the source updates by setting the UpdateSourceTrigger property. 有关更多信息,请参见UpdateSourceTriggerSee UpdateSourceTrigger for more information.

请参阅See also