MainViewModel :
public class MainViewModel : ViewModelBase
{
public ObservableCollection<string> ComboItems { get; set; }
public ICollectionView EmpDB { get; set; }
public ObservableCollection<Employees> _allEmps { get; set; }
private string _SelectedItemFromComboBox;
public string SelectedItemFromComboBox
{
get { return _SelectedItemFromComboBox; }
set
{
SetValue(ref _SelectedItemFromComboBox, value);
EmpDB.Refresh();
OnPropertyChanged("EmpCount");
}
}
public int EmpCount
{
get
{
return EmpDB.OfType<Employees>().ToList().Where(x => x.Age > 50).Count();
}
}
public MainViewModel()
{
DataAccess d = new DataAccess();
_allEmps = d.Emp;
ComboItems = new ObservableCollection<string>(_allEmps.Select(b => b.Name).Distinct().OrderBy(b => b).ToList());
EmpDB = new ListCollectionView(_allEmps)
{
Filter = o => ((Employees)o).Name == SelectedItemFromComboBox
};
}
}
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.
[5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html