@@ -5,20 +5,27 @@ namespace Singulink.UI.Navigation.WinUI;
55/// <content>
66/// Provides dialog related implementations for the navigator.
77/// </content>
8- partial class Navigator
8+ partial class Navigator : IDialogPresenter
99{
10- /// <inheritdoc cref="IDialogPresenter.ShowDialogAsync{TViewModel}(TViewModel )"/>
11- public async Task ShowDialogAsync < TViewModel > ( TViewModel viewModel ) where TViewModel : class , IDialogViewModel
10+ /// <inheritdoc cref="IDialogPresenter.ShowDialogAsync(IDialogViewModel )"/>
11+ public async Task ShowDialogAsync ( IDialogViewModel viewModel )
1212 {
1313 await ShowDialogAsync ( null , viewModel ) ;
1414 }
1515
16- internal async Task ShowDialogAsync < TViewModel > ( ContentDialog ? requestingParentDialog , TViewModel viewModel ) where TViewModel : class , IDialogViewModel
16+ /// <inheritdoc cref="IDialogPresenter.ShowDialogAsync{TResult}(IDialogViewModel{TResult})"/>
17+ public async Task < TResult > ShowDialogAsync < TResult > ( IDialogViewModel < TResult > viewModel )
18+ {
19+ await ShowDialogAsync ( null , viewModel ) ;
20+ return viewModel . Result ;
21+ }
22+
23+ internal async Task ShowDialogAsync ( ContentDialog ? requestingParentDialog , IDialogViewModel viewModel )
1724 {
1825 EnsureThreadAccess ( ) ;
1926
2027 if ( _blockDialogs )
21- throw new InvalidOperationException ( "Show dialog requested at an invalid time while dialogs are blocked." ) ;
28+ throw new InvalidOperationException ( "Show dialog requested at an invalid time while showing dialogs is blocked." ) ;
2229
2330 EnsureDialogIsTopDialog ( requestingParentDialog ) ;
2431 CloseLightDismissPopups ( ) ;
@@ -76,11 +83,10 @@ internal void CloseDialog(ContentDialog dialog)
7683 dialogInfo . Tcs . SetResult ( ) ;
7784 }
7885
79- private ContentDialog CreateDialogFor < TViewModel > ( TViewModel viewModel )
80- where TViewModel : class , IDialogViewModel
86+ private ContentDialog CreateDialogFor ( IDialogViewModel viewModel )
8187 {
82- if ( ! _viewModelTypeToDialogActivator . TryGetValue ( typeof ( TViewModel ) , out var ctorFunc ) )
83- throw new KeyNotFoundException ( $ "No dialog registered for view model of type '{ typeof ( TViewModel ) } '.") ;
88+ if ( ! _viewModelTypeToDialogActivator . TryGetValue ( viewModel . GetType ( ) , out var ctorFunc ) )
89+ throw new KeyNotFoundException ( $ "No dialog registered for view model of type '{ viewModel . GetType ( ) } '.") ;
8490
8591 var dialog = ctorFunc . Invoke ( ) ;
8692 dialog . DataContext = viewModel ;
@@ -140,11 +146,8 @@ async void OnDialogClosing(ContentDialog sender, ContentDialogClosingEventArgs a
140146
141147 // Make sure we are still the top dialog and another event didn't close the dialog after the yield.
142148
143- if ( _dialogStack . TryPeek ( out dialogInfo ) && dialogInfo . Dialog == sender &&
144- MixinManager . GetNavigator ( dismissibleVm ) is { } navigator && ! navigator . TaskRunner . IsBusy )
145- {
146- await navigator . TaskRunner . RunAsBusyAsync ( dismissibleVm . OnDismissRequestedAsync ( ) ) ;
147- }
149+ if ( _dialogStack . TryPeek ( out dialogInfo ) && dialogInfo . Dialog == sender && ! dismissibleVm . TaskRunner . IsBusy )
150+ await dismissibleVm . TaskRunner . RunAsBusyAsync ( dismissibleVm . OnDismissRequestedAsync ( ) ) ;
148151 }
149152 }
150153 }
0 commit comments