mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-13 17:22:47 -05:00
33 lines
838 B
C#
33 lines
838 B
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace Common.Wpf.ExtendedListBoxControl
|
|
{
|
|
public class ExtendedListBox : ListBox
|
|
{
|
|
protected override DependencyObject GetContainerForItemOverride()
|
|
{
|
|
return new ExtendedListBoxItem();
|
|
}
|
|
|
|
private int _lastSelectedIndex = -1;
|
|
|
|
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
|
|
{
|
|
base.OnSelectionChanged(e);
|
|
|
|
if (SelectedIndex == -1 && _lastSelectedIndex != -1)
|
|
{
|
|
int itemCount = Items.Count;
|
|
|
|
if (_lastSelectedIndex >= itemCount)
|
|
_lastSelectedIndex = itemCount - 1;
|
|
|
|
SelectedIndex = _lastSelectedIndex;
|
|
}
|
|
|
|
_lastSelectedIndex = SelectedIndex;
|
|
}
|
|
}
|
|
}
|