0
問題:不設置到對象的實例如何referesh內容在列表框,以避免未將對象引用設置到對象的實例
對象引用(在單擊某個項目在GridView中第二次) 。
此對象以某種方式引用UoMCollection.Clear()和此處遇到的問題:txtBlkUoM.Text = Uom.UoM.ToString();
-1-- Declare this in the page ObservableCollection UoMCollection = new ObservableCollection(); -2-- Gridview : Click an item in GridView, it will do the following: PopUpItem.IsOpen = true; (this is the popUp Box) GetAllUoMForThisItem(No); -2-- This will fill up another ListBox calls : lsBoxUoM private async void GetAllUoMForThisItem(string No) { var db = new SQLiteAsyncConnection(DBPath); (I need to clear the content each time an item selected in GridView) UoMCollection.Clear(); var allUoM = await db.QueryAsync("Select * From ItemUoM Where ItemNo = '" + No + "'"); foreach (var _UoM in allUoM) { string strUoM = _UoM.UoM; AddToList(strUoM); } lsBoxUoM.ItemsSource = null; lsBoxUoM.ItemsSource = UoMCollection; } private void AddToList(string uom) { UoMCollection.Add(new ItemUoM() { UoM = uom }); } -3-- Make a selection in this PopUpBox private void lsBoxUoM_SelectionChanged(object sender, SelectionChangedEventArgs e) { if(lsBoxUoM.SelectedIndex == -1); var Uom = (ItemUoM)lsBoxUoM.SelectedItem; txtBlkUoM.Text = Uom.UoM.ToString(); } -4- Close this PopBox after a selection is made and Start from (2) again