public MainWindowModel() { _testDataSource = new TestDataSource(); TestModels = new ReactiveList<TestModel>(); TestViewModels = TestModels.CreateDerivedCollection(m => { var vm = new TestViewModel { Id = m.Id, Name = m.Name, OtherValue = "", OriginalModel = m }; vm.DoStuffWithThisCommand.Subscribe(x => DoStuff(x as TestViewModel)); return vm; }, m => true, (m, vm) => 0); SetUpDataCommand = ReactiveCommand.CreateAsyncTask(_ => _testDataSource.GetTests()); SetUpDataCommand.Subscribe(results => { using (SuppressChangeNotifications()) { TestModels.Clear(); foreach (var model in results) TestModels.Add(model); } }); }
private TestViewModel CreateTestViewModelFromTestModel(TestModel m) { var vm = new TestViewModel { Id = m.Id, Name = m.Name, OtherValue = "", OriginalModel = m }; vm.DoStuffWithThisCommand.Subscribe(x => DoStuff(x as TestViewModel)); return vm; }
private void DoStuff(TestViewModel vm) { TestModels.Remove(vm.OriginalModel); }