private static void OnContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ContentPresenter source = d as ContentPresenter;
Debug.Assert(source != null,
"The source is not an instance of ContentPresenter!");
object newValue = e.NewValue;
if (newValue is UIElement)
source.ClearValue (ContentPresenter.DataContextProperty);
else
source.DataContext = newValue;
// If the content is a UIElement, we have to clear the Template and wait for a re-render
// Otherwise we directly update the text in our textbox.
if (e.OldValue is UIElement || newValue is UIElement) {
source.InvalidateMeasure ();
source.ClearRoot ();
}
}
#endregion Content