I’ve a data template for ListBoxItem which contains of few buttons, and few custom controls like Grid or Chart. Each button is bound to an appropriate command handler, SelectedIndex property of a ListView control is bound to ViewModel’s propery as well.
The problem: in command handlers (which are bound to buttons) I can’t resolve currently selected item/index because it is not changing whilst clicking on a button or an other control within a ListBox item, but when I clicking on ListBoxItem area itself – SelectedIndex is changing.
Question is how to trigger SelectedIndex to be changed whilst clicking on any control within ListBoxItem?
Add this to your
ListBox.ResourcesEDIT
The previous method only makes the ListBoxItem selected for as long as it has keyboard focus. If you move focus out of the ListBoxItem, it becomes unselected again.
Here’s another simple way to select a ListBox item when the keyboard focus moves within the item, and it stays selected when focus is moved out of the ListBoxItem
And in the Code Behind