本文介绍了UWP-ListBoxItem-单击触发器.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有ListBox的UWP应用程序.当我单击相关的列表框项目时,我会更改框架内容. (我正在为此使用SelectionChanged事件.)在此框架内,我可以执行多项操作,例如移至另一个页面框架. (并保持sme listboxItem处于选中状态.)

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. )

所以我有-> MainPage-> ContactsPage-> ContactsDetailPage. (在列表框中,我选择了联系人"项).但是,如果在"ContactsDetailsPage"上单击"Contacts" ListBoxItem,则SelectionChanged不会触发(因为已选中).因此,我无法导航到联系"页面.

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.

还有另外一个事件,当我单击ListBoxItem时可以用来导航吗?还是您可以建议其他选择?

There is another event I can use to navigate when I click on ListBoxItem ? Or do you can suggest another options ?

谢谢!

推荐答案

您可以始终在逻辑之后将index设置为-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;
    }

这篇关于UWP-ListBoxItem-单击触发器.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 00:32