Browse Source

Merge pull request #11782 from AvaloniaUI/fixes/11617-change-selection-in-selection-changed

Fix changing selection source in selection changed
pull/11798/head
Max Katz 3 years ago
committed by GitHub
parent
commit
0e9bb723e5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .ncrunch/MobileSandbox.Browser.v3.ncrunchproject
  2. 5
      .ncrunch/WindowsInteropTest.net461.v3.ncrunchproject
  3. 5
      .ncrunch/WindowsInteropTest.net6.0-windows.v3.ncrunchproject
  4. 2
      src/Avalonia.Controls/Selection/SelectionModel.cs
  5. 21
      tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs

5
.ncrunch/MobileSandbox.Browser.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>

5
.ncrunch/WindowsInteropTest.net461.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>

5
.ncrunch/WindowsInteropTest.net6.0-windows.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>

2
src/Avalonia.Controls/Selection/SelectionModel.cs

@ -277,7 +277,7 @@ namespace Avalonia.Controls.Selection
{
if (base.Source != value)
{
if (_operation is not null)
if (_operation?.UpdateCount > 0)
{
throw new InvalidOperationException("Cannot change source while update is in progress.");
}

21
tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs

@ -300,6 +300,27 @@ namespace Avalonia.Controls.UnitTests.Selection
target.Source = new[] { 1, 2, 3 };
}
[Fact]
public void Can_Change_Source_In_SelectedItem_Change_Handler()
{
// Issue #11617
var target = CreateTarget();
var raised = 0;
target.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(target.SelectedItem) && raised == 0)
{
++raised;
target.Source = new[] { "foo", "baz", "bar" };
}
};
target.SelectedIndex = 1;
Assert.Equal(-1, target.SelectedIndex);
}
}
public class SelectedIndex

Loading…
Cancel
Save