diff --git a/demo/Ursa.Demo/ViewModels/SplashViewModel.cs b/demo/Ursa.Demo/ViewModels/SplashViewModel.cs index c8a7178..76d894c 100644 --- a/demo/Ursa.Demo/ViewModels/SplashViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/SplashViewModel.cs @@ -24,14 +24,14 @@ public partial class SplashViewModel: ObservableObject, IDialogContext } else { - RequestClose?.Invoke(this, null); + RequestClose?.Invoke(this, true); return false; } } public void Close() { - RequestClose?.Invoke(this, null); + RequestClose?.Invoke(this, false); } public event EventHandler? RequestClose; diff --git a/demo/Ursa.Demo/Views/MainSplashWindow.axaml.cs b/demo/Ursa.Demo/Views/MainSplashWindow.axaml.cs index b5974ea..662a15e 100644 --- a/demo/Ursa.Demo/Views/MainSplashWindow.axaml.cs +++ b/demo/Ursa.Demo/Views/MainSplashWindow.axaml.cs @@ -14,7 +14,7 @@ public partial class MainSplashWindow : SplashWindow InitializeComponent(); } - protected override async Task CreateNextWindow() + protected override async Task CreateNextWindow() { return new MainWindow() { diff --git a/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml b/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml index b7868e2..1bd5f41 100644 --- a/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml +++ b/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml @@ -1,48 +1,54 @@ - - + + + + + + + + + - - - - - - - - - - - + FontSize="14" + Text="聚焦生产力的美学进化" /> + + + diff --git a/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml.cs b/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml.cs index c25f646..a1bf93b 100644 --- a/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml.cs +++ b/demo/Ursa.Demo/Views/MvvmSplashWindow.axaml.cs @@ -14,11 +14,15 @@ public partial class MvvmSplashWindow : SplashWindow InitializeComponent(); } - protected override async Task CreateNextWindow() + protected override async Task CreateNextWindow() { - return new MainWindow() + if (this.DialogResult is true) { - DataContext = new MainViewViewModel() - }; + return new MainWindow() + { + DataContext = new MainViewViewModel() + }; + } + return null; } } \ No newline at end of file diff --git a/src/Ursa/Windows/SplashWindow.cs b/src/Ursa/Windows/SplashWindow.cs index b82cc7d..ee8feb7 100644 --- a/src/Ursa/Windows/SplashWindow.cs +++ b/src/Ursa/Windows/SplashWindow.cs @@ -35,7 +35,8 @@ public abstract class SplashWindow: Window private void OnContextRequestClose(object? sender, object? args) { - Close(args); + DialogResult = args; + Close(); } protected override void OnLoaded(RoutedEventArgs e) @@ -46,9 +47,11 @@ public abstract class SplashWindow: Window DispatcherTimer.RunOnce(Close, CountDown.Value); } } + + protected object? DialogResult { get; private set; } protected virtual Task CanClose() => Task.FromResult(true); - protected abstract Task CreateNextWindow(); + protected abstract Task CreateNextWindow(); private bool _canClose; @@ -62,16 +65,17 @@ public abstract class SplashWindow: Window if (_canClose) { var nextWindow = await CreateNextWindow(); - if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) + if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime && nextWindow is not null) { lifetime.MainWindow = nextWindow; } - nextWindow.Show(); + nextWindow?.Show(); Close(); if (DataContext is IDialogContext idc) { - idc.Close(); + // unregister in advance in case developer try to raise event again. idc.RequestClose -= OnContextRequestClose; + idc.Close(); } return; }