您可以将此代码用于MVVM Pattern
XAML
视图模型
private ObservableCollectiondeleteHistoryListBox = new ObservableCollection (); public ObservableCollection DeleteHistoryListBox { get { return deleteHistoryListBox; } set { deleteHistoryListBox = value; this.RaisePropertyChanged("DeleteHistoryListBox"); } } private HistoryItems deleteHistorySelectedItem; public HistoryItems DeleteHistorySelectedItem { get { return deleteHistorySelectedItem; } set { var selectedItems = DeleteHistoryListBox.Where(x => x.IsSelected).Count(); this.RaisePropertyChanged("DeleteHistorySelectedItem"); } }
类
public class HistoryItems : INotifyPropertyChanged { private string item; public string Item { get { return item; } set { item = value; this.RaisePropertyChanged("Item"); } } private bool isSelected; public bool IsSelected { get { return isSelected; } set { isSelected = value; this.RaisePropertyChanged("IsSelected"); } } }