internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences precedence) { if (o == null) { this.Log().Warn("Style.ApplyTo - Applied to null object - Skipping"); return; } using (DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence)) { var flattenedSetters = CreateSetterMap(); #if !HAS_EXPENSIVE_TRYFINALLY try #endif { ResourceResolver.PushNewScope(_xamlScope); foreach (var pair in flattenedSetters) { pair.Value(o); } } #if !HAS_EXPENSIVE_TRYFINALLY finally #endif { ResourceResolver.PopScope(); } } }
internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences precedence) { if (o == null) { this.Log().Warn("Style.ApplyTo - Applied to null object - Skipping"); return; } using (DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence)) { var flattenedSetters = CreateSetterMap(); #if !HAS_EXPENSIVE_TRYFINALLY try #endif { ResourceResolver.PushNewScope(_xamlScope); foreach (var pair in flattenedSetters) { pair.Value(o); } // Check tree for resource binding values, since some Setters may have set ThemeResource-backed values (o as IDependencyObjectStoreProvider) !.Store.UpdateResourceBindings(isThemeChangedUpdate: false); } #if !HAS_EXPENSIVE_TRYFINALLY finally #endif { ResourceResolver.PopScope(); } } }
private IDisposable RegisterCompiledBindingsUpdates() // Compiled bindings propagation is performed through all non-FrameworkElement providers // to avoid executing this code twice because all FrameworkElement instances call // ApplyCompiledBindings when FrameworkElement.Loading is raised. => ActualInstance is IFrameworkElement ? null : DependencyObjectExtensions.RegisterCompiledBindingsUpdateCallback(Parent, ApplyCompiledBindings);
/// <summary> /// Clears the current style from the specified dependency object. /// </summary> /// <param name="dependencyObject">The target dependency object</param> /// <remarks> /// This method should be included in the calls to update of the Style /// property. Automatic style removal is not implemented for now because /// of breaking changes. /// </remarks> internal void ClearStyle(DependencyObject dependencyObject) { var type = dependencyObject.GetType(); foreach (var setter in CreateSetterMap()) { if (setter.Key is DependencyProperty dp) { DependencyObjectExtensions.ClearValue(dependencyObject, dp, Precedence); } } }
internal View DequeueTemplate(FrameworkTemplate template) { var list = GetTemplatePool(template); View instance; if (list.Count == 0) { if (_trace.IsEnabled) { _trace.WriteEventActivity(TraceProvider.CreateTemplate, EventOpcode.Send, new[] { ((Func <View>)template).Method.DeclaringType.ToString() }); } if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().Debug($"Creating new template, id={GetTemplateDebugId(template)} IsPoolingEnabled:{IsPoolingEnabled}"); } instance = template.LoadContent() ?? new Grid(); if (IsPoolingEnabled && instance is IFrameworkElement) { DependencyObjectExtensions.RegisterParentChangedCallback((DependencyObject)instance, template, OnParentChanged); } } else { int position = list.Count - 1; instance = list[position].Control; list.RemoveAt(position); if (_trace.IsEnabled) { _trace.WriteEventActivity(TraceProvider.ReuseTemplate, EventOpcode.Send, new[] { instance.GetType().ToString() }); } if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().Debug($"Recycling template, id={GetTemplateDebugId(template)}, {list.Count} items remaining in cache"); } } #if USE_HARD_REFERENCES if (IsPoolingEnabled) { _activeInstances.Add(instance); } #endif return(instance); }
internal void ClearInvalidProperties(DependencyObject dependencyObject, Style incomingStyle, DependencyPropertyValuePrecedences precedence) { var oldSetters = CreateSetterMap(); var newSetters = incomingStyle?.CreateSetterMap(); foreach (var kvp in oldSetters) { if (kvp.Key is DependencyProperty dp) { if (newSetters == null || !newSetters.ContainsKey(dp)) { DependencyObjectExtensions.ClearValue(dependencyObject, dp, precedence); } } } }
public void ApplyTo(DependencyObject o) { if (o == null) { this.Log().Warn("Style.ApplyTo - Applied to null object - Skipping"); return; } using (DependencyObjectExtensions.OverrideLocalPrecedence(o, Precedence)) { var flattenedSetters = CreateSetterMap(); foreach (var pair in flattenedSetters) { pair.Value(o); } } }
internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences precedence) { if (o == null) { this.Log().Warn("Style.ApplyTo - Applied to null object - Skipping"); return; } var localPrecedenceDisposable = DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence); var flattenedSetters = CreateSetterMap(); #if !HAS_EXPENSIVE_TRYFINALLY try #endif { ResourceResolver.PushNewScope(_xamlScope); // This block is a manual enumeration to avoid the foreach pattern // See https://github.com/dotnet/runtime/issues/56309 for details var settersEnumerator = flattenedSetters.GetEnumerator(); while (settersEnumerator.MoveNext()) { settersEnumerator.Current.Value(o); } // Check tree for resource binding values, since some Setters may have set ThemeResource-backed values (o as IDependencyObjectStoreProvider) !.Store.UpdateResourceBindings(isThemeChangedUpdate: false); } #if !HAS_EXPENSIVE_TRYFINALLY finally #endif { ResourceResolver.PopScope(); localPrecedenceDisposable?.Dispose(); } }