Last active
November 30, 2018 20:59
-
-
Save yavor87/2170a54b25de1bb3428338c27076b9ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainViewModel : ViewModelBase | |
{ | |
private ObservableCollection<Employee> _data; | |
public ObservableCollection<Employee> Data | |
{ | |
get => _data; | |
set | |
{ | |
if (_data == value) | |
return; | |
_data = value; | |
this.RaisePropertyChanged(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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