public void AddDataSource(DataSource ds) { if (ds.Model != this) { throw new Exception("This data source does not belong to this model."); } _sources.Add(ds); }
// add a data source to the model void _btnAddSource_Click(object sender, RoutedEventArgs e) { var ds = new DataSource(Model); var dlg = new ModalDialog("Add Data Source", new DataSourceEditor(), ds); dlg.ShowDialog(MessageBoxButton.OKCancel); dlg.Closed += (ss, ee) => { if (!ee.Cancel) { Model.AddDataSource(ds); } }; }
void DataSources_CurrentChanged(object sender, EventArgs e) { if (_ds != null) { _ds.Tables.CurrentChanged -= Tables_CurrentChanged; } _ds = _vm.DataSources.CurrentItem as DataSource; if (_ds != null) { _ds.Tables.CurrentChanged += Tables_CurrentChanged; } OnCanExecuteChanged(); }