public CategoryRowViewModel(MasterCategoryRowViewModel masterCategory, Category category, BudgetEditorViewModel budgetEditor) { InitializeRelayCommands(); MasterCategory = masterCategory; _category = category; _budgetEditor = budgetEditor; _categoryMonthViews = new TransformingObservableCollection <BudgetMonthViewModel, CategoryMonthViewModel>( _budgetEditor.VisibleMonthViews, v => { //BudgetMonthView holds it's own copy of the Budget and Categories so you have to match them up based on entityId //instead of ReferenceEquals on the instance BudgetMonthView view = v.BudgetMonthView; MasterCategoryMonthView masterView = view.MasterCategories.Where(mcv => mcv.MasterCategory.EntityID == category.Parent.EntityID).Single(); var categoryMonthView = masterView.Categories.Where(c => c.Category.EntityID == _category.EntityID).SingleOrDefault(); if (categoryMonthView != null) { return(new CategoryMonthViewModel(v, this, categoryMonthView)); } else { return(new CategoryMonthViewModel(v, this, masterView, _category.EntityID)); } }, cmv => { cmv.Dispose(); }); }
public MasterCategoryMonthViewModel(BudgetEditorViewModel budgetEditor, BudgetMonthViewModel budgetMonthViewModel, MasterCategoryRowViewModel masterCategoryRow, MasterCategoryMonthView masterCategoryMonthView) { _budgetEditor = budgetEditor ?? throw new ArgumentNullException(nameof(budgetEditor)); _budgetMonthViewModel = budgetMonthViewModel ?? throw new ArgumentNullException(nameof(budgetMonthViewModel)); _masterCategoryRow = masterCategoryRow ?? throw new ArgumentNullException(nameof(masterCategoryRow)); MasterCategoryMonthView = masterCategoryMonthView ?? throw new ArgumentNullException(nameof(masterCategoryMonthView)); }
private void CategoryCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (CategoryMonthView item in e.NewItems) { if (item.Category.EntityID == _categoryId) { CategoryMonthView = item; _masterCategoryMonthView.Categories.CollectionChanged -= CategoryCollectionChanged; _masterCategoryMonthView = null; _categoryId = null; } } } }
private void InitializeMonthViews() { _masterCategoryMonthViews = new TransformingObservableCollection <BudgetMonthViewModel, MasterCategoryMonthViewModel>( _budgetEditor.VisibleMonthViews, v => { //BudgetMonthView holds it's own copy of the Budget and Categories so you have to match them up based on entityId //instead of ReferenceEquals on the instance BudgetMonthView view = v.BudgetMonthView; MasterCategoryMonthView masterView = view.MasterCategories.Where(mcv => mcv.MasterCategory.EntityID == _masterCategory.EntityID).SingleOrDefault(); if (masterView != null) { return(new MasterCategoryMonthViewModel(_budgetEditor, v, this, masterView)); } else { return(new MasterCategoryMonthViewModel(_budgetEditor, v, this, view, _masterCategory.EntityID)); } }, cmv => { }); }
private void RegisterForCallBack(MasterCategoryMonthView masterCategoryMonthView, string categoryId) { _masterCategoryMonthView = masterCategoryMonthView; _categoryId = categoryId; masterCategoryMonthView.Categories.CollectionChanged += CategoryCollectionChanged; }
public CategoryMonthViewModel(BudgetMonthViewModel budgetMonthViewModel, CategoryRowViewModel categoryRowViewModel, MasterCategoryMonthView masterCategoryMonthView, string categoryId) { BudgetMonthViewModel = budgetMonthViewModel; CategoryRowViewModel = categoryRowViewModel; RegisterForCallBack(masterCategoryMonthView, categoryId); }