mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-14 01:25:37 -05:00
Initial commit
This commit is contained in:
32
ExtendedListBoxControl/ExtendedListBox.cs
Normal file
32
ExtendedListBoxControl/ExtendedListBox.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user