Files
docs-desktop/dotnet-desktop-guide/framework/wpf/data/how-to-set-up-notification-of-binding-updates.md
T
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

2.3 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Set Up Notification of Binding Updates 03/30/2017
notifications [WPF], binding updates
data binding [WPF], notification of binding updates
binding [WPF], updates [WPF], notifications of
5673073e-dbe1-49da-980a-484a88f9595a

How to: Set Up Notification of Binding Updates

This example shows how to set up to be notified when the binding target (target) or the binding source (source) property of a binding has been updated.

Example

user interface (UI) that it should update, because the bound data has changed. Note that for these events to work, and also for one-way or two-way binding to work properly, you need to implement your data class using the xref:System.ComponentModel.INotifyPropertyChanged interface. For more information, see Implement Property Change Notification.

Set the xref:System.Windows.Data.Binding.NotifyOnTargetUpdated%2A or xref:System.Windows.Data.Binding.NotifyOnSourceUpdated%2A property (or both) to true in the binding. The handler you provide to listen for this event must be attached directly to the element where you want to be informed of changes, or to the overall data context if you want to be aware that anything in the context has changed.

Here is an example that shows how to set up for notification when a target property has been updated.

[!code-xamlDirectionalBinding#2]

You can then assign a handler based on the EventHandler<T> delegate, OnTargetUpdated in this example, to handle the event:

[!code-csharpDirectionalBinding#3]
[!code-csharpDirectionalBinding#EndEvent]

Parameters of the event can be used to determine details about the property that changed (such as the type or the specific element if the same handler is attached to more than one element), which can be useful if there are multiple bound properties on a single element.

See also