diff --git a/docs/tutorials/music-store-app/opening-a-dialog.md b/docs/tutorials/music-store-app/opening-a-dialog.md index f6906f77b..527a767b7 100644 --- a/docs/tutorials/music-store-app/opening-a-dialog.md +++ b/docs/tutorials/music-store-app/opening-a-dialog.md @@ -145,8 +145,13 @@ private async Task DoShowDialogAsync(InteractionContext - action(ViewModel!.ShowDialog.RegisterHandler(DoShowDialogAsync))); +this.WhenActivated(action => +{ + if (viewModel != null) + { + action(ViewModel!.ShowDialog.RegisterHandler(DoShowDialogAsync))); + } +} ``` This means that whenever the main window view is activated, the `DoShowDialogAsync` handler is registered. The action is disposable, so that _ReactiveUI_ can clean up the registration when the main window view is not on the screen. @@ -167,7 +172,12 @@ namespace Avalonia.MusicStore.Views { InitializeComponent(); this.WhenActivated(action => - action(ViewModel!.ShowDialog.RegisterHandler(DoShowDialogAsync))); + { + if (viewModel != null) + { + action(ViewModel!.ShowDialog.RegisterHandler(DoShowDialogAsync))); + } + } } private async Task DoShowDialogAsync(InteractionContext