Skip to content

Instantly share code, notes, and snippets.

@yavor87
Last active November 30, 2018 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yavor87/2170a54b25de1bb3428338c27076b9ac to your computer and use it in GitHub Desktop.
Save yavor87/2170a54b25de1bb3428338c27076b9ac to your computer and use it in GitHub Desktop.
public class MainViewModel : ViewModelBase
{
private ObservableCollection<Employee> _data;
public ObservableCollection<Employee> Data
{
get => _data;
set
{
if (_data == value)
return;
_data = value;
this.RaisePropertyChanged();
}
}
}
private void RefreshData(object obj)
{
this.Data = this.GenerateRandomData();
}
static DataView GetSampleView()
{
DataTable table = new DataTable();
table.Columns.Add("Weight", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(57, "Koko", "Shar Pei", DateTime.Now);
table.Rows.Add(130, "Fido", "Bullmastiff", DateTime.Now);
return table.DefaultView;
}
public MainViewModel()
{
_data = new ObservableCollection<Employee>(SampleData.Employees);
_dataView = new QueryableCollectionView(_data); // Wrap data in a collection view
}
public QueryableCollectionView Data => _dataView;
private void OnFilterData(object obj)
{
var descriptor = new FilterDescriptor(nameof(Employee.LastName), FilterOperator.StartsWith, "P");
_dataView.FilterDescriptors.Add(descriptor);
}
private void OnSortData(object obj)
{
var descriptor = new SortDescriptor() { Member = nameof(Employee.LastName), SortDirection = ListSortDirection.Descending };
_dataView.SortDescriptors.Add(descriptor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment