System.Windows.Controls.ContentPresenter.OnContentPropertyChanged C# (CSharp) Method

OnContentPropertyChanged() private static method

ContentProperty property changed handler.
private static OnContentPropertyChanged ( DependencyObject d, DependencyPropertyChangedEventArgs e ) : void
d DependencyObject ContentPresenter that changed its Content.
e DependencyPropertyChangedEventArgs DependencyPropertyChangedEventArgs.
return void
		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