diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
index a5bbcec186..69da211aa4 100644
--- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
+++ b/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();
}
///
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();
}
///
@@ -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
{
private readonly List _list = new List();