UWP - ListBoxItem - Click Trigger.

守給你的承諾、 提交于 2019-12-12 04:56:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!