diff --git a/src/Avalonia.Controls/Automation/Peers/ListItemAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ListItemAutomationPeer.cs index ac23873e6aa..85f139a6a3f 100644 --- a/src/Avalonia.Controls/Automation/Peers/ListItemAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/ListItemAutomationPeer.cs @@ -36,7 +36,7 @@ public void Select() if (Owner.Parent is SelectingItemsControl parent) { - var index = parent.ItemContainerGenerator.IndexFromContainer(Owner); + var index = parent.IndexFromContainer(Owner); if (index != -1) parent.SelectedIndex = index; @@ -50,7 +50,7 @@ void ISelectionItemProvider.AddToSelection() if (Owner.Parent is ItemsControl parent && parent.GetValue(ListBox.SelectionProperty) is ISelectionModel selectionModel) { - var index = parent.ItemContainerGenerator.IndexFromContainer(Owner); + var index = parent.IndexFromContainer(Owner); if (index != -1) selectionModel.Select(index); diff --git a/src/Avalonia.Controls/Automation/Peers/SelectingItemsControlAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/SelectingItemsControlAutomationPeer.cs index 7ae0ba7244f..11480fcb34a 100644 --- a/src/Avalonia.Controls/Automation/Peers/SelectingItemsControlAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/SelectingItemsControlAutomationPeer.cs @@ -35,7 +35,7 @@ protected SelectingItemsControlAutomationPeer(SelectingItemsControl owner) foreach (var i in selection.SelectedIndexes) { - var container = owner.ItemContainerGenerator.ContainerFromIndex(i); + var container = owner.ContainerFromIndex(i); if (container is Control c && c.IsAttachedToVisualTree) { diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs index aeaf94d7284..b7a298bb16f 100644 --- a/src/Avalonia.Controls/ComboBox.cs +++ b/src/Avalonia.Controls/ComboBox.cs @@ -399,12 +399,12 @@ private void TryFocusSelectedItem() var selectedIndex = SelectedIndex; if (IsDropDownOpen && selectedIndex != -1) { - var container = ItemContainerGenerator.ContainerFromIndex(selectedIndex); + var container = ContainerFromIndex(selectedIndex); if (container == null && SelectedIndex != -1) { ScrollIntoView(Selection.SelectedIndex); - container = ItemContainerGenerator.ContainerFromIndex(selectedIndex); + container = ContainerFromIndex(selectedIndex); } if (container != null && CanFocus(container)) diff --git a/src/Avalonia.Controls/MenuBase.cs b/src/Avalonia.Controls/MenuBase.cs index 1918964bc89..da7a36fa73e 100644 --- a/src/Avalonia.Controls/MenuBase.cs +++ b/src/Avalonia.Controls/MenuBase.cs @@ -84,13 +84,13 @@ public bool IsOpen { var index = SelectedIndex; return (index != -1) ? - (IMenuItem?)ItemContainerGenerator.ContainerFromIndex(index) : + (IMenuItem?)ContainerFromIndex(index) : null; } set { SelectedIndex = value is Control c ? - ItemContainerGenerator.IndexFromContainer(c) : -1; + IndexFromContainer(c) : -1; } } diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index aeee6f8410b..5588bde7c03 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -13,7 +13,6 @@ using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.LogicalTree; -using Avalonia.VisualTree; namespace Avalonia.Controls { @@ -319,12 +318,12 @@ public bool StaysOpenOnClick { var index = SelectedIndex; return (index != -1) ? - (IMenuItem?)ItemContainerGenerator.ContainerFromIndex(index) : + (IMenuItem?)ContainerFromIndex(index) : null; } set { - SelectedIndex = value is Control c ? ItemContainerGenerator.IndexFromContainer(c) : -1; + SelectedIndex = value is Control c ? IndexFromContainer(c) : -1; } } @@ -691,7 +690,7 @@ private void PopupOpened(object? sender, EventArgs e) if (selected != -1) { - var container = ItemContainerGenerator?.ContainerFromIndex(selected); + var container = ContainerFromIndex(selected); container?.Focus(); } } diff --git a/src/Avalonia.Controls/TabControl.cs b/src/Avalonia.Controls/TabControl.cs index 33089344e8a..f12a66a4e6f 100644 --- a/src/Avalonia.Controls/TabControl.cs +++ b/src/Avalonia.Controls/TabControl.cs @@ -195,7 +195,7 @@ private void UpdateSelectedContent() else { var container = SelectedItem as IContentControl ?? - ItemContainerGenerator.ContainerFromIndex(SelectedIndex) as IContentControl; + ContainerFromIndex(SelectedIndex) as IContentControl; SelectedContentTemplate = container?.ContentTemplate; SelectedContent = container?.Content; } diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index 2fc901438d5..67e0d854360 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -575,7 +575,7 @@ protected override void OnKeyDown(KeyEventArgs e) { var previous = (TreeViewItem)parentItemsControl.ContainerFromIndex(index - 1)!; result = previous.IsExpanded && previous.ItemCount > 0 ? - (TreeViewItem)previous.ItemContainerGenerator.ContainerFromIndex(previous.ItemCount - 1)! : + (TreeViewItem)previous.ContainerFromIndex(previous.ItemCount - 1)! : previous; } else