I am writing an application with a list that allows you to use multiple selection (SelectionMode = Multiple); items in lisbox are ingredients for the recipe.
Unfortunately, clicking on a list item allows you to select this item, which may be undesirable. I need the following script:
- the user clicks on the list to select the list (the list itself, not the item)
- user scrolls the desired item and selects it
What I did was ListBoxItem style including checkbox and ContentPresenter (like this blog post ). However, clicking on an ingredient name selects it. Thus, I delay the MouseDown event in the text block containing the ingredient name, find the base ListBoxItem, call Focus () on it and set the Handled property of the event to true.
The Listbox item now has focus but is not selected. Using the up and down keys indicates that the focus was on the desired item. My problem is that the user does not see that he clicked on the correct item. A dashed rectangle is not displayed on this element. Here is the result:

And here is what I would like:

I tried calling private WPF methods, such as KeyboardNavigation.ShowFocusVisual, I tried to send keystrokes to the list (when a person did it by pressing the right cursor key or Alt key, a dotted box will appear).
Any idea?
source share