/// <summary> /// Initializes a new instance of the <see cref="TermListViewModel"/> class. /// </summary> /// <param name="termsService">A service that allows to access a storage of glossary terms.</param> /// <param name="editViewModel">A model of a view to edit terms.</param> public TermListViewModel(ITermsService termsService, ITermEditViewModel editViewModel) { if (termsService == null) { throw new ArgumentNullException("termsService"); } if (editViewModel == null) { throw new ArgumentNullException("editViewModel"); } this._termsService = termsService; this.EditViewModel = editViewModel; // Create view of term collection sorted by Name. var termsView = new ListCollectionView(this._terms); termsView.SortDescriptions.Add(new SortDescription( PropertyExpressionHelper.GetName <Term, string>(_ => _.Name), ListSortDirection.Ascending)); this._termsView = termsView; this._termsViewContext = new DispatcherSynchronizationContext(termsView.Dispatcher); // Create commands. this._addTerm = new RelayCommand( _ => this.AddTermExecuted(), _ => !this.IsBusy && !this.IsEditMode); this._editTerm = new RelayCommand( p => this.EditTermExecuted(p), p => !this.IsBusy && !this.IsEditMode && this._terms.Contains(p)); this._deleteTerm = new RelayCommand( _ => this.DeleteTermExecuted(), p => !this.IsBusy && this._editingTerm != null); this._accept = new RelayCommand( _ => this.AcceptExecuted(), _ => !this.IsBusy && this.IsEditMode); this._cancel = new RelayCommand( _ => this.CancelExecuted(), _ => !this.IsBusy && this.IsEditMode); this._recreateStorage = new RelayCommand( _ => this.RecreateStorageExecuted(), _ => this._isInvalidStorage); this.StartLoadTerms(); }
/// <summary> /// Initializes a new instance of the <see cref="TermListViewModelDraft"/> class. /// </summary> /// <param name="termsService">A service that allows to access a storage of glossary terms.</param> /// <param name="editViewModel">A model of a view to edit terms.</param> public TermListViewModelDraft(ITermsService termsService, ITermEditViewModel editViewModel) : base(termsService, editViewModel) { }
/// <summary> /// Initializes a new instance of the <see cref="TermListViewModel"/> class /// and ensures that terms were loaded from the service. /// </summary> /// <param name="termsService">A service that allows to access a storage of glossary terms.</param> /// <param name="editViewModel">A model of a view to edit terms.</param> private static TermListViewModel CreateViewModelLoaded(ITermsService termsService, ITermEditViewModel editViewModel) { var model = new TermListViewModel(termsService, editViewModel); DispatcherHelper.ProcessCurrentQueue(); return(model); }