0
votes

I have listbox bound to a collection of PhoneEntity. I also have a Remove button and it's command's CanExecute returns true if the listbox's SelectedItem != null. Pretty standard.

When I select a list item, the Remove button is enabled. But when I attempt to click the button, as soon as the button receives the focus on mouse down, the listbox's SelectedItem becomes null, so the button disables and cannot be clicked.

How do I keep the lisbox's selected item even if the list loses focus?

Thanks

1
Normally, the SelectedItem property does not depend on the keyboard focus. Are there any event handlers for the LostFocus event or similar events that modify the list box when keyboard focus changes? - user128300
No, there are no events. There's no code at all except the command, which is what makes this strange. - CoderForHire

1 Answers

0
votes

It isn't pretty but... make a global variable to hold the selection index. Handle the on selection change and assign the selected index. Then handle the onFocusLost event and set the selection to that global variable.