1. 程式人生 > >wpf 給listview的數據源轉換為集合

wpf 給listview的數據源轉換為集合

報錯 引用 interface cti items void item inter 移除

目的是點擊某個按鈕把一條數據從 itemssource中移除

private void delete_Click_1(object sender, RoutedEventArgs e)

{
DtsInterfaceItemInfo dtsfice= (DtsInterfaceItemInfo)(sender as FrameworkElement).DataContext; 獲取點擊的那列的按鈕獲取該列的數據
//(this.listview.ItemsSource as List<DtsInterfaceItemInfo>).Remove(dtsfice); 原

(this.listview.ItemsSource as ObservableCollection<DtsInterfaceItemInfo>).Remove(dtsfice); 改後

}

原來報錯,改後正常

ObservableCollection需要引用using System.Collections.ObjectModel;

wpf 給listview的數據源轉換為集合