Initial commit

This commit is contained in:
2014-04-30 17:33:21 -04:00
commit f965f46fb3
33 changed files with 2949 additions and 0 deletions

View 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;
}
}
}

View File

@@ -0,0 +1,75 @@
using System.Windows.Controls;
using System.Windows.Input;
using Common.Wpf.Extensions;
namespace Common.Wpf.ExtendedListBoxControl
{
public class ExtendedListBoxItem : ListBoxItem
{
#region Helper properties
public ExtendedListBox ParentListBox
{
get
{
return this.GetAncestor<ExtendedListBox>();
}
}
#endregion
#region Fix selection handling for multiple selection
private bool _fireMouseDownOnMouseUp;
private SelectionMode? _selectionMode;
private SelectionMode SelectionMode
{
get
{
if (_selectionMode == null)
{
// Get the parent list box
ListBox listBox = ParentListBox;
// Cache the selection mode
_selectionMode = listBox.SelectionMode;
}
return _selectionMode.Value;
}
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
// If the item is already selected we want to ignore the mouse down now and raise it on mouse up instead
if (SelectionMode != SelectionMode.Single && IsSelected)
{
_fireMouseDownOnMouseUp = true;
return;
}
// Call the normal mouse down
base.OnMouseLeftButtonDown(e);
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
// If we ignored the earlier mouse down we need to fire it now
if (SelectionMode != SelectionMode.Single && _fireMouseDownOnMouseUp)
{
// Call the normal mouse down
base.OnMouseLeftButtonDown(e);
// Clear the flag
_fireMouseDownOnMouseUp = false;
}
// Call the normal mouse up
base.OnMouseLeftButtonUp(e);
}
#endregion
}
}