Esempio n. 1
0
        // Property invalidation callback invoked when TemplateProperty is invalidated
        private static void OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentPresenter cp = (ContentPresenter)d;

            UpdateTemplateCache(cp, (FrameworkTemplate)e.OldValue, (FrameworkTemplate)e.NewValue, TemplateProperty);

            if (cp.IsConnectedToLiveTree)
            {
                cp.InvalidateMeasureInternal();
            }
        }
Esempio n. 2
0
        // Property invalidation callback invoked when TemplateProperty is invalidated
        private static void OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentPresenter cp = (ContentPresenter)d;

            UpdateTemplateCache(cp, (FrameworkTemplate)e.OldValue, (FrameworkTemplate)e.NewValue, TemplateProperty);

            if (VisualTreeHelper.GetParent(cp) != null)
            {
                cp.InvalidateMeasureInternal();
            }
        }
Esempio n. 3
0
        private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentPresenter ctrl = (ContentPresenter)d;

            // if we're already marked to reselect the template, there's nothing more to do
            if (!ctrl._templateIsCurrent)
            {
                return;
            }

            bool mismatch;

            if (ctrl.ContentTemplate != null)
            {
                mismatch = false; // explicit template - do not re-apply
            }
            else if (ctrl.Template == UIElementContentTemplate)
            {
                mismatch      = true; // direct template - always re-apply
                ctrl.Template = null; // and release the old content so it can be re-used elsewhere
            }
            else if (ctrl.Template == DefaultContentTemplate)
            {
                mismatch = true; // default template - always re-apply
            }
            else
            {
                // implicit template - re-apply if content type changed
                Type oldDataType = e.OldValue?.GetType();
                Type newDataType = e.NewValue?.GetType();

                mismatch = (oldDataType != newDataType);
            }

            // if the content and (old) template don't match, reselect the template
            if (mismatch)
            {
                ctrl._templateIsCurrent = false;
            }

            // keep the DataContext in sync with Content
            if (ctrl._templateIsCurrent && ctrl.Template != UIElementContentTemplate)
            {
                ctrl.DataContext = e.NewValue;
            }

            if (ctrl.IsConnectedToLiveTree)
            {
                ctrl.InvalidateMeasureInternal();
            }
        }
Esempio n. 4
0
        private static void OnContentTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentPresenter ctrl = (ContentPresenter)d;

            ctrl._templateIsCurrent = false;

            // if ContentTemplate is really changing, remove the old template
            ctrl.Template = null;

            if (ctrl.IsConnectedToLiveTree)
            {
                ctrl.InvalidateMeasureInternal();
            }
        }