ソースを参照

Fix setting SelectedIndex in XAML

Benedikt Schroeder 6 年 前
コミット
bcbe9c3dbd
1 ファイル変更12 行追加4 行削除
  1. 12 4
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

+ 12 - 4
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@@ -304,6 +304,11 @@ namespace Avalonia.Controls.Primitives
         {
             base.ItemsCollectionChanged(sender, e);
 
+            if (_updateCount > 0)
+            {
+                return;
+            }
+
             switch (e.Action)
             {
                 case NotifyCollectionChangedAction.Add:
@@ -1071,13 +1076,16 @@ namespace Avalonia.Controls.Primitives
 
         private void UpdateFinished()
         {
-            if (_updateSelectedIndex != int.MinValue)
+            if (_updateSelectedItem != null)
             {
-                SelectedIndex = _updateSelectedIndex;
+                SelectedItem = _updateSelectedItem;
             }
-            else if (_updateSelectedItem != null)
+            else
             {
-                SelectedItem = _updateSelectedItem;
+                if (ItemCount > 0)
+                {
+                    SelectedIndex = _updateSelectedIndex != int.MinValue ? _updateSelectedIndex : 0;
+                }
             }
         }