Browse Source

Unify SelectingItemsControl init handling and add extra checks to ensure correctness.

pull/3444/head
Dariusz Komosiński 6 years ago
parent
commit
a238fd33f0
  1. 38
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

38
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -5,6 +5,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Generators;
@ -240,17 +241,14 @@ namespace Avalonia.Controls.Primitives
public override void BeginInit()
{
base.BeginInit();
++_updateCount;
_updateSelectedIndex = int.MinValue;
InternalBeginInit();
}
/// <inheritdoc/>
public override void EndInit()
{
if (--_updateCount == 0)
{
UpdateFinished();
}
InternalEndInit();
base.EndInit();
}
@ -437,7 +435,8 @@ namespace Avalonia.Controls.Primitives
protected override void OnDataContextBeginUpdate()
{
base.OnDataContextBeginUpdate();
++_updateCount;
InternalBeginInit();
}
/// <inheritdoc/>
@ -445,10 +444,7 @@ namespace Avalonia.Controls.Primitives
{
base.OnDataContextEndUpdate();
if (--_updateCount == 0)
{
UpdateFinished();
}
InternalEndInit();
}
protected override void OnKeyDown(KeyEventArgs e)
@ -1118,6 +1114,26 @@ namespace Avalonia.Controls.Primitives
}
}
private void InternalBeginInit()
{
if (_updateCount == 0)
{
_updateSelectedIndex = int.MinValue;
}
++_updateCount;
}
private void InternalEndInit()
{
Debug.Assert(_updateCount > 0);
if (--_updateCount == 0)
{
UpdateFinished();
}
}
private class Selection : IEnumerable<int>
{
private readonly List<int> _list = new List<int>();

Loading…
Cancel
Save