Windows phone 7 列表框项未被激发

Windows phone 7 列表框项未被激发,windows-phone-7,listbox,click,listitem,Windows Phone 7,Listbox,Click,Listitem,我在panorama中使用listbox,就像panorama有5个项目,那么每个panorama项目都包含一个listbox listitem有时不会被触发,主要是第二次。第一种情况是,单击列表项后,它会导航到下一页。当我回来再点击列表项时,我不会被解雇 我正在为列表单击侦听器使用SelectionChanged 我从web search得到一个建议,在中使用stackpannel而不是grid,但在某些地方,由于组件的排列,我无法使用stackpannel 请建议我改变stackpannel

我在panorama中使用listbox,就像panorama有5个项目,那么每个panorama项目都包含一个listbox

listitem有时不会被触发,主要是第二次。第一种情况是,单击列表项后,它会导航到下一页。当我回来再点击列表项时,我不会被解雇

我正在为列表单击侦听器使用SelectionChanged

我从web search得到一个建议,在中使用stackpannel而不是grid,但在某些地方,由于组件的排列,我无法使用stackpannel

请建议我改变stackpannel是唯一的方法还是有其他解决方案


欢迎任何想法。

当在列表框中选择一个项目时,它会保留所选索引的记录。当再次点击相同的元素时,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;
        }
    }

非常感谢,伙计。这在所有其他页面都有效。但只有在一个页面中,我有一个问题,列表框在panorama的数据模板中。我无法访问它。我有5个全景项目,每个项目有一个列表框。