Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update opening-a-dialog.md #547

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs/tutorials/music-store-app/opening-a-dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ private async Task DoShowDialogAsync(InteractionContext<MusicStoreViewModel,
- Add the following code to the end of the constructor:

```csharp
this.WhenActivated(action =>
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.
Expand All @@ -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<MusicStoreViewModel,
Expand Down