Skip to content

Commit

Permalink
fix: ItemContainerGenerator obsolete member after AvaloniaUI#9677
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering committed Jan 19, 2023
1 parent bf85f4d commit 5cc0edb
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/MenuBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/Avalonia.Controls/MenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.VisualTree;

namespace Avalonia.Controls
{
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/TabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/TreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5cc0edb

Please sign in to comment.