internal override UIElement GetDefaultTemplate() { ContentControl templateOwner = TemplateOwner as ContentControl; if (templateOwner != null) { if (DependencyProperty.UnsetValue == ReadLocalValue(ContentPresenter.ContentProperty)) { SetTemplateBinding(ContentPresenter.ContentProperty, new TemplateBindingExpression { SourceProperty = ContentControl.ContentProperty, TargetProperty = ContentPresenter.ContentProperty }); } if (DependencyProperty.UnsetValue == ReadLocalValue(ContentPresenter.ContentTemplateProperty)) { SetTemplateBinding(ContentPresenter.ContentTemplateProperty, new TemplateBindingExpression { SourceProperty = ContentControl.ContentTemplateProperty, TargetProperty = ContentPresenter.ContentTemplateProperty }); } } // Expand the ContentTemplate if it exists DataTemplate template = ContentTemplate; if (template != null) { _contentRoot = template.GetVisualTree(this) as UIElement; } else { var content = Content; _contentRoot = content as UIElement; if (_contentRoot == null && content != null) { _contentRoot = FallbackRoot; } } return(_contentRoot); }