private void BeginEditThreshold() { var dataContext = this.DataContext as FanConfigViewModel; var viewModel = this.thresholdsGrid.SelectedValue as TemperatureThresholdViewModel; if (viewModel != null && dataContext != null) { var clonedViewModel = viewModel.Clone() as TemperatureThresholdViewModel; clonedViewModel.Parent = dataContext; var dialog = new TemperatureThresholdWindow() { DataContext = clonedViewModel, Owner = this }; if (dialog.ShowDialog() == true) { dataContext.TemperatureThresholds.Replace(viewModel, clonedViewModel); } } }
private void addThreshold_Click(object sender, RoutedEventArgs e) { var dataContext = this.DataContext as FanConfigViewModel; if (dataContext != null) { var viewModel = new TemperatureThresholdViewModel() { Parent = dataContext }; var dialog = new TemperatureThresholdWindow() { DataContext = viewModel, Owner = this }; if (dialog.ShowDialog() == true) { dataContext.TemperatureThresholds.Add(viewModel); } } }