/// <summary> /// Called to inform the list box that one of its items was clicked. /// </summary> /// <param name="container">The item container that was clicked.</param> internal void HandleItemClicked(ListBoxItem container) { switch (SelectionMode) { case SelectionMode.Single: HandleItemClickedSingle(container); break; case SelectionMode.Multiple: HandleItemClickedMultiple(container); break; } }
/// <summary> /// Handles clicking on an item when the list box is in single selection mode. /// </summary> /// <param name="item">The item that was clicked.</param> private void HandleItemClickedSingle(ListBoxItem item) { BeginChangeSelection(); if (GetIsSelected(item)) { if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { UnselectContainer(item); } } else { UnselectAllItems(); SelectContainer(item); } EndChangeSelection(); }
/// <summary> /// Handles clicking on an item when the list box is in multiple selection mode. /// </summary> /// <param name="item">The item that was clicked.</param> private void HandleItemClickedMultiple(ListBoxItem item) { var selected = GetIsSelected(item); if (selected) { UnselectContainer(item); } else { SelectContainer(item); } }
/// <summary> /// Selects the specified item and scrolls it into view. /// </summary> private void HandleItemClickedAndScrollIntoView(ListBoxItem item, Boolean buffer = true) { HandleItemClicked(item); ItemsControlUtil.ScrollItemIntoView<ListBoxItem>(this, PART_ScrollViewer, item, buffer); }