Files
docs-desktop/dotnet-desktop-guide/framework/wpf/data/how-to-set-up-notification-of-binding-updates.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.6 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

[!INCLUDETLA#tla_winclient] raises a data update event each time that the binding source or target has been updated. Internally, this event is used to inform the [!INCLUDETLA#tla_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