// Token: 0x06004420 RID: 17440 RVA: 0x00136834 File Offset: 0x00134A34
        private void EnsureTemplate()
        {
            DataTemplate template     = this.Template;
            DataTemplate dataTemplate = null;

            this._templateIsCurrent = false;
            while (!this._templateIsCurrent)
            {
                this._templateIsCurrent = true;
                dataTemplate            = this.ChooseTemplate();
                if (template != dataTemplate)
                {
                    this.Template = null;
                }
                if (dataTemplate != ContentPresenter.UIElementContentTemplate)
                {
                    base.DataContext = this.Content;
                }
                else
                {
                    base.ClearValue(FrameworkElement.DataContextProperty);
                }
            }
            this.Template = dataTemplate;
            if (template == dataTemplate)
            {
                StyleHelper.DoTemplateInvalidations(this, template);
            }
        }
Exemple #2
0
        //------------------------------------------------------
        //
        //  Private methods
        //
        //------------------------------------------------------

        private void EnsureTemplate()
        {
            DataTemplate oldTemplate = Template;
            DataTemplate newTemplate = null;

            for (_templateIsCurrent = false; !_templateIsCurrent;)
            {
                // normally this loop will execute exactly once.  The only exception
                // is when setting the DataContext causes the ContentTemplate or
                // ContentTemplateSelector to change, presumably because they are
                // themselves data-bound (see bug 128119).  In that case, we need
                // to call ChooseTemplate again, to pick up the new template.
                // We detect this case because _templateIsCurrent is reset to false
                // in OnContentTemplate[Selector]Changed, causing a second iteration
                // of the loop.
                _templateIsCurrent = true;
                newTemplate        = ChooseTemplate();

                // if the template is changing, it's important that the code that cleans
                // up the old template runs while the CP's DataContext is still set to
                // the old Content.  The way to get this effect is:
                //      a. change the template to null
                //      b. change the data context
                //      c. change the template to the new value

                if (oldTemplate != newTemplate)
                {
                    Template = null;
                }

                if (newTemplate != UIElementContentTemplate)
                {
                    // set data context to the content, so that the template can bind to
                    // properties of the content.
                    this.DataContext = Content;
                }
                else
                {
                    // If we're using the content directly, clear the data context.
                    // The content expects to inherit.
                    this.ClearValue(DataContextProperty);
                }
            }

            Template = newTemplate;

            // if the template didn't change, we still need to force the content for the template to be regenerated;
            // so call StyleHelper's DoTemplateInvalidations directly
            if (oldTemplate == newTemplate)
            {
                StyleHelper.DoTemplateInvalidations(this, oldTemplate);
            }
        }