2013-04-04 69 views
0

我在全景圖中使用列表框,就好像全景圖有5個項目,那麼每個全景圖項目都包含一個列表框。列表框項不會被解僱

listitem不會在有時被解僱,主要是第二次。對於第一次點擊列表項目時,它將導航到下一頁。當我回來時,我點擊listitem並沒有被解僱。

正在使用SelectionChanged作爲列表單擊監聽器。

我有一個網絡搜索的建議,使用stackpannel而不是網格,但在某些地方由於組件安排無法使用堆棧pannel。

請建議我更改爲stackpannel是唯一的方法或有任何其他解決方案。

歡迎任何形式的想法。

回答

2

當在列表框中選擇了一個項目時,它將保留選定索引的記錄。當再次點擊相同的元素時,所選索引中沒有變化,因此SelectionChanged不會被觸發。因此,你可以做的是每次選擇後或後退導航到列表框中頁面

//In the onnavigatedto function, set the listbox selectedindex to -1 
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     MyListBox.SelectedIndex = -1; 
    } 

和修改您這樣

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 
     } 
    } 

希望SelectionChanged事件這有助於

後設置的selectedIndex回-1

UPDATE:爲了您的全景案例

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; 
     } 
    } 
+0

非常感謝好友。這在所有其他頁面都有效。但只有在一個頁面中,我有一個問題,列表框在全景圖的數據模板內。我無法訪問它。我有5個全景物品,每個物品有1個列表框。 – arnp 2013-04-04 09:59:21

+0

檢查更新的答案! – nkchandra 2013-04-04 10:42:36

+0

美妙的兄弟..你的代碼有效。 – arnp 2013-04-04 11:26:18