private void Update <T0, T1>(string propertyName, ItemListViewModel <T0> parent, ItemListViewModel <T1> child, Action loadAction) where T0 : class where T1 : class { if (propertyName == "SelectedItem") { if (parent.SelectedItem == null) { child.SetItems(Enumerable.Empty <T1>()); } else { loadAction(); } } }
public ArcDurationCalculationViewModel(IEventAggregator eventAggregator, IDataService dataService, ICalculatorService calculatorService, IUnityContainer unityContainer) { //events _eventAggregator = eventAggregator; _eventAggregator.GetEvent <CalculationInputUpdated>().Subscribe(UpdateCalculationInput); _eventAggregator.GetEvent <CalculationOutputUpdated>().Subscribe(UpdateCalculationOutput); _eventAggregator.GetEvent <ArcDurationUpdated>().Subscribe(UpdateArcDuration); //data service _dataService = dataService; //calc service _calculatorService = calculatorService; //container _unityContainer = unityContainer; Manufacturers = new ItemListViewModel <Manufacturer>(); BreakerStyles = new ItemListViewModel <BreakerStyle>(); TripUnitTypes = new ItemListViewModel <TripUnitType>(); LongTimeDelays = new ItemListViewModel <LongTimeDelay>(); ShortTimePickups = new ItemListViewModel <ShortTimePickup>(); ShortTimeDelays = new ItemListViewModel <ShortTimeDelay>(); Instantaneous = new ItemListViewModel <Instantaneous>(); Manufacturers.PropertyChanged += (s, e) => Update(e.PropertyName, Manufacturers, BreakerStyles, LoadBreakerTypes); BreakerStyles.PropertyChanged += (s, e) => Update(e.PropertyName, BreakerStyles, TripUnitTypes, LoadTripUnitTypes); TripUnitTypes.PropertyChanged += (s, e) => Update(e.PropertyName, TripUnitTypes, LongTimeDelays, LoadLongTimeDelays); TripUnitTypes.PropertyChanged += (s, e) => Update(e.PropertyName, TripUnitTypes, ShortTimePickups, LoadShortTimePickups); TripUnitTypes.PropertyChanged += (s, e) => Update(e.PropertyName, TripUnitTypes, ShortTimeDelays, LoadShortTimeDelays); TripUnitTypes.PropertyChanged += (s, e) => Update(e.PropertyName, TripUnitTypes, Instantaneous, LoadInstantaneous); //load manufacturers Manufacturers.SetItems(_dataService.GetManufacturers()); //commands CanceModalCommand = new DelegateCommand(CancelModal); NextCommand = new RelayCommand(ClickNext, CanClickNext); }