public MainWindowViewModel(IConfiguration configuration) { InterestPlanViewModels = new ObservableCollection <InterestPlanViewModel>(); InterestPlanViewModels.CollectionChanged += InterestPlanViewModels_CollectionChanged; var options = configuration.Get <Rootobject>() ?? new Rootobject(); InitiateOptions(options); options.InterestPlanViewModelOptions.ForEach(ip => AddInterestPlanViewModel(new InterestPlanViewModel(ip))); SelectedCulture = CultureInfo.GetCultureInfo(options.CultureInfo); Cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); CreateWindowCommand = new DelegateCommand(() => CreateWindow?.Invoke()); AddInterestPlanCommand = new DelegateCommand(() => { var p = new InterestPlanViewModel(InterestPlanViewModelOption.GetExample1()); AddInterestPlanViewModel(p); SelectedInterestPlanViewModelIndex = InterestPlanViewModels.IndexOf(p); }); DeleteInterestPlanCommand = new DelegateCommand( () => { var interestPlanViewModel = InterestPlanViewModels.ElementAt(SelectedInterestPlanViewModelIndex); interestPlanViewModel.PropertyChanged -= InterestPlanViewModel_PropertyChanged; InterestPlanViewModels.Remove(interestPlanViewModel); }, () => InterestPlanViewModels.Count > 1 ); ResetAllCommand = new DelegateCommand(() => InterestPlanViewModels.ToList().ForEach(ip => ip.ResetCommand.Execute())); CalculateAllCommand = new DelegateCommand(() => InterestPlanViewModels.ToList().ForEach(ip => ip.CalculateCommand.Execute())); ResetAllCommand.Execute(); }
private void AddInterestPlanViewModel(InterestPlanViewModel interestPlanViewModel) { interestPlanViewModel.PropertyChanged += InterestPlanViewModel_PropertyChanged; InterestPlanViewModels.Add(interestPlanViewModel); }