using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; namespace SelectableVirtualList { public class ViewModel : INotifyPropertyChanged { public ObservableCollection<Employee> SelectedEmployeeCollection { get; set; } private SelectableVirtualList<Employee> _AvailableEmployeeCollection; public SelectableVirtualList<Employee> AvailableEmployeeCollection { get { return _AvailableEmployeeCollection; } set { _AvailableEmployeeCollection = value; OnPropertyChanged("AvailableEmployeeCollection"); } } public ViewModel() { AvailableEmployeeCollection = new SelectableVirtualList<Employee>(new EmployeeObjectGenerator()); SelectedEmployeeCollection = new ObservableCollection<Employee>(); } public void Add() { IList<Employee> employees = AvailableEmployeeCollection.SelectedList; foreach (var employee in employees) { employee.IsSelected = false; if (!SelectedEmployeeCollection.Contains(employee)) { SelectedEmployeeCollection.Add(employee); } AvailableEmployeeCollection.Remove(employee); } } public void Remove() { int internalStandardCount = SelectedEmployeeCollection.Count; for (int i = internalStandardCount - 1; i >= 0; i--) { Employee answerInstance = SelectedEmployeeCollection[i]; if (answerInstance.IsSelected) { answerInstance.IsSelected = false; if (!AvailableEmployeeCollection.Contains(answerInstance)) { AvailableEmployeeCollection.Add(answerInstance); } SelectedEmployeeCollection.Remove(answerInstance); } } } public void SelectAvailableList() { AvailableEmployeeCollection.SelectAll(); OnPropertyChanged("AvailableEmployeeCollection"); } public void DeselectAvailableList() { AvailableEmployeeCollection.DeSelectAll(); OnPropertyChanged("AvailableEmployeeCollection"); } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); } } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)