Hello. There is a slight difficulty with implementing a custom menu. I use wpf, prism and mvvm. The shell has 2 regions - main and menu. When modules are loaded into a menu (NavBarControl, DevExpress), the views that represent menu items (NavBarGroup) are registered. Each item contains items (NavBarItem) to which commands are attached. When the user selects NavBarItem, the associated command is run. Some commands allow you to create new entities, but for this they need to get data from the server. When this data is loaded, the application should be responsive. While I came to this decision:
this.createAccount.Command = (ICommand)new DelegateCommand(this.ExecuteCreateAccount); private void ExecuteCreateAccount() { AppEvent.OnShowNotificationEvent(UTNotificationType.ChangeMainLoaderStatus, "show", null); if (this.isCreateAccountProcessing) { return; } this.isCreateAccountProcessing = true; Task.Factory.StartNew(() => this.AccountListViewModel.LoadUsersCollection()).GetAwaiter().OnCompleted(this.ShowAccountEditor); } private void ShowAccountEditor() { AppEvent.OnShowNotificationEvent(UTNotificationType.ChangeMainLoaderStatus, null, null); this.isCreateAccountProcessing = false; if (this.createAccount.IsSelected) { this.AccountListViewModel.CreateNewItem(); } }
Is there a better implementation of this task? When a background operation is processed, I show a loader (AppEvent.OnShowNotificationEvent). If the user selects another menu item, the command should be canceled (I don’t show the editor window).