public AddNewSectionPageViewModel(ISectionsStorage sectionsStorage, Section parent) { this.sectionsStorage = sectionsStorage; this.parent = parent; AddNewSectionCommand = new RelayCommand(OnAddNewSectionCommandExecute); }
public MainPage(ISectionsStorage sectionsStorage) { this.sectionsStorage = sectionsStorage; InitializeComponent(); DataContext = new MainPageViewModel(sectionsStorage, AutofacContainer.Resolve <IEventAggregator>()); }
public EditSectionPageViewModel(ISectionsStorage sectionsStorage, Section section) { this.sectionsStorage = sectionsStorage; this.section = section; Name = section.Name; AddNewSectionCommand = new RelayCommand(() => { section.Name = Name; sectionsStorage.Save(); Complete?.Invoke(this, EventArgs.Empty); }); }
public MainPageViewModel(ISectionsStorage sectionsStorage, IEventAggregator eventAggregator) { this.sectionsStorage = sectionsStorage; this.eventAggregator = eventAggregator; root = null; ShowAddSectionDialogCommand = new RelayCommand(() => { var result = AutofacContainer.Resolve <IDialogService>().Show <AddNewSectionPage>(new AddNewSectionPageViewModel(sectionsStorage, root)); if (result == true) { Sections = new ObservableCollection <Section>(root?.Children ?? sectionsStorage.Sections); OnPropertyChanged(nameof(Sections)); } }); EditSectionCommand = new RelayCommand <Section>(s => { var result = AutofacContainer.Resolve <IDialogService>().Show <AddNewSectionPage>(new EditSectionPageViewModel(sectionsStorage, s)); if (result == true) { Sections = new ObservableCollection <Section>(sectionsStorage.Sections); OnPropertyChanged(nameof(Sections)); } }); DeleteSectionCommand = new RelayCommand <Guid>(guid => { if (MessageBox.Show("Удалить раздел, включая все подразделы?", "Удаление раздела", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { sectionsStorage.RemoveSection(guid); Sections = new ObservableCollection <Section>(sectionsStorage.Sections); OnPropertyChanged(nameof(Sections)); } }); OpenSectionCommand = new RelayCommand <Section>(section => { Sections = new ObservableCollection <Section>(section.Children); root = section; eventAggregator.GetEvent <SectionChangedEvent>().Publish(section); OnPropertyChanged(nameof(Sections)); }); CloseSectionCommand = new RelayCommand(() => { if (root == null) { return; } if (root.Parent == null) { Sections = new ObservableCollection <Section>(sectionsStorage.Sections); } else { Sections = new ObservableCollection <Section>(root.Parent.Children ?? sectionsStorage.Sections); } OnPropertyChanged(nameof(Sections)); root = root.Parent; eventAggregator.GetEvent <SectionChangedEvent>().Publish(root); }); sectionsStorage.Load(); Sections = new ObservableCollection <Section>(sectionsStorage.Sections); }