예제 #1
0
        /// <summary>
        /// ContentTemplateProperty property changed handler.
        /// </summary>
        /// <param name="d">ContentPresenter that changed its ContentTemplate.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        private static void OnContentTemplatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentPresenter source = d as ContentPresenter;

            Debug.Assert(source != null,
                         "The source is not an instance of ContentPresenter!");

            // Use the Content as the DataContext to enable bindings in
            // ContentTemplate or clear it if we removed our template (NOTE:
            // this should use ClearValue instead when it's available).
            source.DataContext = e.NewValue != null ? source.Content : null;

            // Display the Content
            source.PrepareContentPresenter();
        }
예제 #2
0
        /// <summary>
        /// ContentProperty property changed handler.
        /// </summary>
        /// <param name="d">ContentPresenter that changed its Content.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        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!");

            // Use the Content as the DataContext to enable bindings in
            // ContentTemplate
            if (source.ContentTemplate != null)
            {
                source.DataContext = e.NewValue;
            }

            // Display the Content
            source.PrepareContentPresenter();
        }