public SampleDataProvider() { InitializeComponent(); var objectDataProv = FindResource("src") as DataSourceProvider; myResources = objectDataProv.Data as PeopleSource; }
private void Delete() { if (PeopleSource.SelectedIndex >= 0) { if (MessageBox.Show($"Delete {PeopleSource.SelectedItem.Person.FirstName}?", "Question", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { PeopleSource.RemoveAt(PeopleSource.SelectedIndex); } } }
public void TestSource() { IPerson addedPerson; using (var source = new PeopleSource()) { addedPerson = source.Add("Test two"); } using (var source = new PeopleSource()) { var foundPerson = source.Query.FirstOrDefault(p => p.PersonId == addedPerson.PersonId); Assert.AreEqual("Test two", foundPerson.Name, "Person not found via query"); source.Delete(foundPerson.PersonId); } }
/// <summary> /// Creates new instance of TreeViewViewModel class /// </summary> public TreeViewViewModel() { // instantiate data source mSource = new PeopleSource(); // instantiate command GroupingSelectionCommand = new RelayCommand <GroupingSelection>(selectedGroup => { // save selected grouping mode mGroupingType = selectedGroup; // inform subscribers about the DataSource property change if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs("DataSource")); } }); }
private void Load() { // for demo, in real app use a data service for example var people = new InitItemCollection <PersonViewModel>(); for (int i = 0; i < 3; i++) { var viewModel = this.PeopleSource.CreateNew(); var person = new PersonModel { Id = i + 1, FirstName = $"First.{i}", LastName = $"Last.{i}" }; people.Add(viewModel, person); } PeopleSource.Load(people); }