One of the key line-of-business-app features of Silverlight is the ability to databind – and we use it everywhere.
So it’s slightly odd that the DataContextChanged event is internal in Silverlight (it’s public in WPF). How on earth can we then know if our data context has been changed?
The answer’s pretty simple, and is properly documented on The Problem Solver blog.
The solution is to create a custom DependencyProperty and explicitly bind it, thus:
public partial class PersonHeader : UserControl
// Required to initialize variables
SetBinding(DataContextWatcherProperty, new Binding());
public static readonly DependencyProperty DataContextWatcherProperty =
typeof (Object), typeof (PersonHeader),
private static void DataContextChanged(object sender,
var personHeader = (PersonHeader) sender;
// Update the control as needed