| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ShellDrawerCoordinator.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using MyNet.UI.Dialogs.ContentDialogs; |
| | | 9 | | |
| | | 10 | | namespace MyNet.UI.ViewModels.Shell.Drawers; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Closes shell drawers when a content dialog opens (file dialogs are unaffected). |
| | | 14 | | /// </summary> |
| | | 15 | | public sealed class ShellDrawerCoordinator : IDisposable |
| | | 16 | | { |
| | | 17 | | private readonly IContentDialogService _contentDialogService; |
| | | 18 | | private readonly EventHandler<ContentDialogLifecycleEventArgs> _dialogOpenedHandler; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Initializes a new instance of the <see cref="ShellDrawerCoordinator"/> class. |
| | | 22 | | /// </summary> |
| | | 23 | | public ShellDrawerCoordinator(IContentDialogService contentDialogService, IShellHostProvider hostProvider) |
| | | 24 | | { |
| | 3 | 25 | | ArgumentNullException.ThrowIfNull(contentDialogService); |
| | 3 | 26 | | ArgumentNullException.ThrowIfNull(hostProvider); |
| | | 27 | | |
| | 3 | 28 | | _contentDialogService = contentDialogService; |
| | 3 | 29 | | _dialogOpenedHandler = (_, _) => hostProvider.Current?.CloseDrawers(); |
| | 3 | 30 | | _contentDialogService.DialogOpened += _dialogOpenedHandler; |
| | 3 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | 0 | 34 | | public void Dispose() => _contentDialogService.DialogOpened -= _dialogOpenedHandler; |
| | | 35 | | } |
| | | 36 | | |