O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting a Change of Data Context

The FrameworkElement.DataContext property is a fundamental part of the XAML data-binding system and allows an object to be associated with a top-level element in the visual tree and then inherited by descendants of that element.

Unfortunately, the Windows Phone SDK does not include a public event for detecting when the DataContext of a FrameworkElement is changed. As a workaround, I have included in the downloadable sample code a class named DataContextChangedListener that uses attached properties to emulate a DataContextChanged event, which allows you to receive notification when a FrameworkElement’s data context is changed (see Listing 26.4).

The Subscribe method of the DataContextChangedListener associates ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required