MultiBit Shift-Click icon is not set correctly

Im coming to my mind trying to figure it out. I am experienced in WPF, but I have never seen anything like it.

I have a ListBox that contains selectable ListBoxItems. Items in the list can be selected by clicking the mouse or using the up / down arrows. Im using SelectionMode.Extended, so my list supports several options.

Problem: clicking on an item in the list, then Shift-Clicking on another item selects the correct range of items as you expected. Unfortunately, using the up / down arrows does not work properly - instead, the selected range will always depend on the last CLICKED element, and not the element that was selected using the arrow keys.

For instance:

[Item 1] <- Click this item [Item 2] <- Use the down arrow to select this item [Item 3] <- Shift-Click this item 

You expect items 2 and 3 to be selected, instead all items (1, 2 and 3) will be selected.

All ListBox properties have the correct values ​​(i.e., using the arrow keys it updates the SelectedItems property), my only problem seems to be with the way the ListBox handles the Shift-Click selection inside. As far as I know, I believe that this is due to the fact that the "Multi-select anchor" ListBoxs is installed with the mouse, but not with the arrow keys.

Has anyone come across and solved this before? Is there a way to set the "multi-select anchor" manually? Thanks for your help!

Chris

+4
source share
1 answer

I understood the solution:

To solve this problem, you should set Focus to the element after changing SelectedIndex:

 if (SelectedIndex > 0) { SelectedIndex--; ListBoxItem item = ItemContainerGenerator.ContainerFromIndex(SelectedIndex) as ListBoxItem; item.Focus(); } 

This is how you move the selection in the list. However, you need to set the focus on the element to select a shift click in order to recognize the element as an anchor.

+2
source

Source: https://habr.com/ru/post/1401227/


All Articles