/// <summary> /// Deselects all items in list. /// </summary> /// <param name="list"><see cref="ListViewBase"/></param> public static void DeselectAll(this ListViewBase list) { switch (list.SelectionMode) { case ListViewSelectionMode.Single: list.SelectedItem = null; break; case ListViewSelectionMode.Multiple: case ListViewSelectionMode.Extended: list.DeselectRange(new ItemIndexRange(0, (uint)list.Items.Count)); break; } }
/// <summary> /// Deselects the provided item. /// </summary> /// <typeparam name="T">Type of item.</typeparam> /// <param name="list"><see cref="ListViewBase"/></param> /// <param name="item">Item to deselect.</param> public static void DeselectItem <T>(this ListViewBase list, T item) where T : DependencyObject { switch (list.SelectionMode) { case ListViewSelectionMode.Single: if (list.SelectedItem == item) { list.SelectedItem = null; } break; case ListViewSelectionMode.Multiple: case ListViewSelectionMode.Extended: list.DeselectRange(new ItemIndexRange(list.IndexFromContainer(item), 1)); break; } }