From 3edae5a858078d075371640cc614fcef92ca7960 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 4 Jul 2022 18:24:41 -0400 Subject: [PATCH] Merge pull request #8442 from AvaloniaUI/fixes/empty-batch-update Fix empty batch nested updates. --- src/Avalonia.Base/ValueStore.cs | 4 --- .../AvaloniaObjectTests_BatchUpdate.cs | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Base/ValueStore.cs b/src/Avalonia.Base/ValueStore.cs index 6b7b5980863..eddb5601240 100644 --- a/src/Avalonia.Base/ValueStore.cs +++ b/src/Avalonia.Base/ValueStore.cs @@ -463,10 +463,6 @@ public bool End() values.Remove(entry.property); } } - else - { - throw new AvaloniaInternalException("Value could not be found at the end of batch update."); - } // If a new batch update was started while ending this one, abort. if (_batchUpdateCount > 0) diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs index 01d5752eadc..45de8608949 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs @@ -611,6 +611,36 @@ public void Can_Bind_Completed_Binding_Back_To_Original_Value_When_Ending_Batch_ Assert.Equal("foo", notifications[1].NewValue); } + [Fact] + public void Can_Run_Empty_Batch_Update_When_Ending_Batch_Update() + { + var target = new TestClass(); + var raised = 0; + var notifications = new List(); + + target.Foo = "foo"; + target.Bar = "bar"; + + target.BeginBatchUpdate(); + target.ClearValue(TestClass.FooProperty); + target.ClearValue(TestClass.BarProperty); + target.PropertyChanged += (sender, e) => + { + if (e.Property == TestClass.BarProperty) + { + target.BeginBatchUpdate(); + target.EndBatchUpdate(); + } + + ++raised; + }; + target.EndBatchUpdate(); + + Assert.Null(target.Foo); + Assert.Null(target.Bar); + Assert.Equal(2, raised); + } + public class TestClass : AvaloniaObject { public static readonly StyledProperty FooProperty =