问题
I´ve an UWP application with a ListBox. When I click on a related listboxitem I change a frame content. ( I am using the SelectionChanged event for this. ) Inside this Frame I can go and do multiple operations such as move into another Page Frame. (And keep the sme listboxItem selected. )
So I have -> MainPage -> ContactsPage -> ContactsDetailPage. (On the listBox I have the "Contacts" item selected). But, if on "ContactsDetailsPage" I click on "Contacts" ListBoxItem the SelectionChanged doesnt trigger ( Because it is selected). So, I cannot navigate to "Contact" Page.
There is another event I can use to navigate when I click on ListBoxItem ? Or do you can suggest another options ?
Thank you !
回答1:
You may always set index to -1 after your logic and ignore it when it's fired:
private void ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ListBox.SelectedIndex == -1) return;
//your logic
ListBox.SelectedIndex = -1;
}
来源:https://stackoverflow.com/questions/45812310/uwp-listboxitem-click-trigger