private void LoadNames() { detailGrid.IsEnabled = false; var list = Service.GetCommonNames(Taxon.TaxaID.Value); _model = new ObservableCollection<CommonNameViewModel>(list.ConvertAll(name => { var vm = new CommonNameViewModel(name); vm.DataChanged += new DataChangedHandler((x) => { RegisterPendingChange(new UpdateCommonNameCommand(vm.Model)); }); return vm; })); lstNames.ItemsSource = _model; if (_model.Count > 0) { lstNames.SelectedIndex = 0; } IsPopulated = true; }
private void AddNewName() { CommonName data = new CommonName(); data.BiotaID = Taxon.TaxaID.Value; data.CommonNameID = -1; var viewModel = new CommonNameViewModel(data); viewModel.Name = NextNewName("<Name name {0}>", _model, () => viewModel.Name); _model.Add(viewModel); lstNames.SelectedItem = viewModel; lstNames.ScrollIntoView(viewModel); RegisterPendingChange(new InsertCommonNameCommand(data)); }