Compartilhar via


Como: Especificar a Direção do Vínculo

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.

Exemplo

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.

O exemplo a seguir mostra como definir o Mode propriedade.

<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 Como: 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.

Consulte também

Referência

Binding

Conceitos

Revisão de Associação de Dados

Outros recursos

Data Binding How-to Topics