当在 ListBox 中选择一项时,它会保留 selectedindex 的记录。当再次点击相同的元素时, selectedindex 没有变化,因此不会触发 SelectionChanged。因此,您可以做的是在每次选择后或返回到列表框页面后将 selectedindex 设置回 -1
//In the onnavigatedto function, set the listbox selectedindex to -1
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
MyListBox.SelectedIndex = -1;
}
并像这样修改您的 selectionchanged 事件
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//let our code run only if index is not -1
if (MyListBox.SelectedIndex != -1)
{
//Your selectionchanged code
}
}
希望这可以帮助
更新:对于您的全景案例
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listbox = (sender as ListBox);
//let our code run only if index is not -1
if (listbox.SelectedIndex != -1)
{
//Your selectionchanged code
At the end of it set the index back to -1
listbox.SelectedIndex = -1;
}
}