要如何得知ListBox繫結的資料數量有變化呢?由於資料來源是透過繫結,所以要得知資料量有有更動時必需加入聆聽ListBox.Items.VectorChanged事件。
1: myListBox.Items.VectorChanged += VectorChangedEventHandler;當數量改變時,會呼叫指定的VectorChangedEventHander函式:
1: public void VectorChangedEventHandler(IObservableVector<object> sender, IVectorChangedEventArgs e)
2: { 3: myListBox.Visibility = (sender.Count > 0) ? Visibility.Visible : Visibility.Collapsed; 4: 5: String strValue = String.Format(@"({0})", sender.Count);
6: 7: Debug.WriteLine(strValue); 8: }
沒有留言:
張貼留言