1
votes

I am using a listbox in a data template - and from an earlier post I cannot reference the listbox directly in the code behind.

As a result I am capturing the last selected object in the selectionchanged event for the listbox and using this when I want to navigate.

I now need to also clear the selected object in the listbox -can I do this in the selectionchanged event (after storing it away).

Alternatively I could use the MouseLeftButtonDown event on the listbox (which I understand is the equivalent of a 'click') but can I get the selected object in the listbox in this event.

  • thanks
2

2 Answers

5
votes

In the selection changed event set <ListboxName>.SelectedIndex = -1;

Also, do not use the MouseLeftButtonDown event. This will fire whenever the user touches the ListBox, even if they're just trying to scroll up / down and not actually selecting an item.

1
votes

If you can't change the SelectedIndex in code behind then, instead of detecting the SelectionChanged event you could detect a Tap event on the ListBoxItem.