Пример #1
0
        private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentPresenter cp = (ContentPresenter)d;
            bool             reevaluateTemplate;

            if (cp.ContentTemplate != null)
            {
                reevaluateTemplate = false; // explicit template - do not re-apply
            }
            else if (cp.Template == UIElementContentTemplate)
            {
                reevaluateTemplate = true; // direct template - always re-apply
                cp.Template        = null; // and release the old content so it can be re-used elsewhere
            }
            else
            {
                Debug.Assert(cp.Template == null ||
                             cp.Template == DefaultContentTemplate);
                reevaluateTemplate = true; // default template - always re-apply
            }

            if (e.NewValue is UIElement)
            {
                // If we're using the content directly, clear the data context.
                // The content expects to inherit.
                cp.ClearValue(DataContextProperty);
            }
            else
            {
                // set data context to the content, so that the template can bind to
                // properties of the content.
                cp.DataContext = e.NewValue;
            }

            if (reevaluateTemplate)
            {
                cp.ReevaluateTemplate();
            }
        }
Пример #2
0
        // Token: 0x06000C69 RID: 3177 RVA: 0x0002E674 File Offset: 0x0002C874
        internal static void OnResourcesChanged(DependencyObject d, ResourcesChangeInfo info, bool raiseResourceChangedEvent)
        {
            bool            flag                      = info.Contains(d.DependencyObjectType.SystemType, true);
            bool            isThemeChange             = info.IsThemeChange;
            bool            isStyleResourcesChange    = info.IsStyleResourcesChange;
            bool            isTemplateResourcesChange = info.IsTemplateResourcesChange;
            bool            flag2                     = info.Container == d;
            FrameworkObject frameworkObject           = new FrameworkObject(d);

            if (info.IsResourceAddOperation || info.IsCatastrophicDictionaryChange)
            {
                frameworkObject.SetShouldLookupImplicitStyles();
            }
            if (frameworkObject.IsFE)
            {
                FrameworkElement fe = frameworkObject.FE;
                fe.HasStyleChanged     = false;
                fe.HasStyleInvalidated = false;
                fe.HasTemplateChanged  = false;
                if (info.IsImplicitDataTemplateChange)
                {
                    ContentPresenter contentPresenter = fe as ContentPresenter;
                    if (contentPresenter != null)
                    {
                        contentPresenter.ReevaluateTemplate();
                    }
                }
                if (fe.HasResourceReference)
                {
                    TreeWalkHelper.InvalidateResourceReferences(fe, info);
                    if ((!isStyleResourcesChange && !isTemplateResourcesChange) || !flag2)
                    {
                        TreeWalkHelper.InvalidateStyleAndReferences(d, info, flag);
                    }
                }
                else if (flag && (fe.HasImplicitStyleFromResources || fe.Style == FrameworkElement.StyleProperty.GetMetadata(fe.DependencyObjectType).DefaultValue) && (!isStyleResourcesChange || !flag2))
                {
                    fe.UpdateStyleProperty();
                }
                if (isThemeChange)
                {
                    fe.UpdateThemeStyleProperty();
                }
                if (raiseResourceChangedEvent && fe.PotentiallyHasMentees)
                {
                    fe.RaiseClrEvent(FrameworkElement.ResourcesChangedKey, new ResourcesChangedEventArgs(info));
                    return;
                }
            }
            else
            {
                FrameworkContentElement fce = frameworkObject.FCE;
                fce.HasStyleChanged     = false;
                fce.HasStyleInvalidated = false;
                if (fce.HasResourceReference)
                {
                    TreeWalkHelper.InvalidateResourceReferences(fce, info);
                    if ((!isStyleResourcesChange && !isTemplateResourcesChange) || !flag2)
                    {
                        TreeWalkHelper.InvalidateStyleAndReferences(d, info, flag);
                    }
                }
                else if (flag && (fce.HasImplicitStyleFromResources || fce.Style == FrameworkContentElement.StyleProperty.GetMetadata(fce.DependencyObjectType).DefaultValue) && (!isStyleResourcesChange || !flag2))
                {
                    fce.UpdateStyleProperty();
                }
                if (isThemeChange)
                {
                    fce.UpdateThemeStyleProperty();
                }
                if (raiseResourceChangedEvent && fce.PotentiallyHasMentees)
                {
                    fce.RaiseClrEvent(FrameworkElement.ResourcesChangedKey, new ResourcesChangedEventArgs(info));
                }
            }
        }
Пример #3
0
        private static void OnContentTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ContentPresenter cp = (ContentPresenter)d;

            cp.ReevaluateTemplate();
        }