示例#1
0
        /// <summary>
        /// Sets the templated parent, with the ability to control the propagation of the templated parent.
        /// </summary>
        /// <param name="templatedParent">The parent to apply.</param>
        /// <param name="applyToChildren">
        /// Applies the templated parent to children if true. False is generally used when a control is template-able
        /// to avoid propagating its own templated parent to its children.
        /// </param>
        public void SetTemplatedParent(FrameworkElement templatedParent)
        {
            try
            {
                if (_isApplyingTemplateBindings || _bindingsSuspended)
                {
                    // If we reach this point, this means that a propagation loop has been detected, and
                    // we can skip the current binder.
                    // This can happen if a DependencyObject-typed DependencyProperty contains a reference
                    // to one of its ancestors.
                    return;
                }

                _isApplyingTemplateBindings = true;

                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().DebugFormat(
                        "{0}.ApplyTemplateBindings({1}/{2}) (h:{3:X8})",
                        _originalObjectType.ToString(),
                        templatedParent?.GetType().ToString() ?? "[null]",
                        templatedParent?.GetHashCode().ToString("X8", CultureInfo.InvariantCulture) ?? "[null]",
                        ActualInstance?.GetHashCode()
                        );
                }

                _properties.ApplyTemplatedParent(templatedParent);

                ApplyChildrenBindable(templatedParent, isTemplatedParent: true);
            }
            finally
            {
                _isApplyingTemplateBindings = false;
            }
        }
        public void SetTemplatedParent(FrameworkElement?templatedParent)
        {
#if !HAS_EXPENSIVE_TRYFINALLY
            // The try/finally incurs a very large performance hit in mono-wasm, and SetValue is in a very hot execution path.
            // See https://github.com/mono/mono/issues/13653 for more details.
            try
#endif
            {
                if (_isApplyingTemplateBindings || _bindingsSuspended)
                {
                    // If we reach this point, this means that a propagation loop has been detected, and
                    // we can skip the current binder.
                    // This can happen if a DependencyObject-typed DependencyProperty contains a reference
                    // to one of its ancestors.
                    return;
                }

                _isApplyingTemplateBindings = true;

                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().DebugFormat(
                        "{0}.ApplyTemplateBindings({1}/{2}) (h:{3:X8})",
                        _originalObjectType.ToString(),
                        templatedParent?.GetType().ToString() ?? "[null]",
                        templatedParent?.GetHashCode().ToString("X8", CultureInfo.InvariantCulture) ?? "[null]",
                        ActualInstance?.GetHashCode()
                        );
                }

                _properties.ApplyTemplatedParent(templatedParent);

                ApplyChildrenBindable(templatedParent, isTemplatedParent: true);
            }
#if !HAS_EXPENSIVE_TRYFINALLY
            finally
#endif
            {
                _isApplyingTemplateBindings = false;
            }
        }
示例#3
0
 private string GetOwnerDebugString()
 => ActualInstance?.GetType().ToString() ?? "[collected]";