mirror of
https://github.com/4sval/FModel.git
synced 2026-12-04 23:02:22 -06:00
31 lines
767 B
C#
31 lines
767 B
C#
using System.Windows.Controls;
|
|
|
|
namespace FModel.Extensions;
|
|
|
|
public static class ListBoxExtensions
|
|
{
|
|
public static ListBoxItem RevealItem(this ListBox list, object item)
|
|
{
|
|
var index = list.Items.IndexOf(item);
|
|
if (index < 0)
|
|
return null;
|
|
|
|
list.ApplyTemplate();
|
|
list.UpdateLayout();
|
|
if (list.FindVisualChild<VirtualizingPanel>() is { } panel)
|
|
{
|
|
panel.BringIndexIntoViewPublic(index);
|
|
}
|
|
else
|
|
{
|
|
list.ScrollIntoView(item);
|
|
}
|
|
|
|
list.UpdateLayout();
|
|
var container = list.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
|
|
container?.BringIntoView();
|
|
list.UpdateLayout();
|
|
return container;
|
|
}
|
|
}
|