Explorar o código

Implement SetItems method in ResourceDictionary (#18354)

* Implement AddOrUpdateRange method in ResourceDictionary

* Change to SetItems method nam, remove flag

---------

Co-authored-by: Julien Lebosquain <[email protected]>
StefanKoell hai 7 meses
pai
achega
ce72eced6b
Modificáronse 1 ficheiros con 15 adicións e 1 borrados
  1. 15 1
      src/Avalonia.Base/Controls/ResourceDictionary.cs

+ 15 - 1
src/Avalonia.Base/Controls/ResourceDictionary.cs

@@ -40,7 +40,8 @@ namespace Avalonia.Controls
             set
             {
                 Inner[key] = value;
-                Owner?.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty);
+                Owner?.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty);            
+
             }
         }
 
@@ -150,6 +151,19 @@ namespace Avalonia.Controls
         public void AddNotSharedDeferred(object key, IDeferredContent deferredContent)
             => Add(key, new NotSharedDeferredItem(deferredContent));
 
+        public void SetItems(IEnumerable<KeyValuePair<object, object?>> values)
+        {
+            try
+            {
+                foreach (var value in values)
+                    Inner[value.Key] = value.Value;
+            }
+            finally
+            {
+                Owner?.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty);            
+            }
+        }
+        
         public void Clear()
         {
             if (_inner?.Count > 0)