feat: close directly if next window is null.
This commit is contained in:
@@ -24,14 +24,14 @@ public partial class SplashViewModel: ObservableObject, IDialogContext
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RequestClose?.Invoke(this, null);
|
RequestClose?.Invoke(this, true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
RequestClose?.Invoke(this, null);
|
RequestClose?.Invoke(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler<object?>? RequestClose;
|
public event EventHandler<object?>? RequestClose;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public partial class MainSplashWindow : SplashWindow
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<Window> CreateNextWindow()
|
protected override async Task<Window?> CreateNextWindow()
|
||||||
{
|
{
|
||||||
return new MainWindow()
|
return new MainWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,48 +1,54 @@
|
|||||||
<u:SplashWindow xmlns="https://github.com/avaloniaui"
|
<u:SplashWindow
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
x:Class="Ursa.Demo.Views.MvvmSplashWindow"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:u="https://irihi.tech/ursa"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
xmlns:iri="https://irihi.tech/shared"
|
||||||
xmlns:iri="https://irihi.tech/shared"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d"
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
Width="400" Height="400"
|
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
||||||
CountDown="{x:Null}"
|
Title="MvvmSplashWindow"
|
||||||
x:DataType="viewModels:SplashViewModel"
|
Width="400"
|
||||||
x:Class="Ursa.Demo.Views.MvvmSplashWindow"
|
Height="400"
|
||||||
Title="MvvmSplashWindow">
|
x:DataType="viewModels:SplashViewModel"
|
||||||
<Grid
|
CountDown="{x:Null}"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<Grid
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
ColumnDefinitions="Auto, Auto"
|
||||||
|
RowDefinitions="Auto, Auto, Auto">
|
||||||
|
<iri:IrihiLogo
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="0"
|
||||||
|
Width="64"
|
||||||
|
Margin="0,0,16,0"
|
||||||
|
Fill="{DynamicResource SemiGrey5}" />
|
||||||
|
<StackPanel Grid.Row="0" Grid.Column="1">
|
||||||
|
<TextBlock
|
||||||
|
Classes="H2"
|
||||||
|
Text="铱泓科技"
|
||||||
|
Theme="{DynamicResource TitleTextBlock}" />
|
||||||
|
<TextBlock FontWeight="Bold" Text="IRIHI Technology" />
|
||||||
|
</StackPanel>
|
||||||
|
<ProgressBar
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.ColumnSpan="2"
|
||||||
|
Margin="0,16,0,0"
|
||||||
|
Value="{Binding Progress}" />
|
||||||
|
<StackPanel
|
||||||
|
Grid.Row="2"
|
||||||
|
Grid.Column="0"
|
||||||
|
Grid.ColumnSpan="2">
|
||||||
|
<TextBlock
|
||||||
|
Margin="0,12,0,0"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
FontSize="14"
|
||||||
ColumnDefinitions="Auto, Auto"
|
Text="聚焦生产力的美学进化" />
|
||||||
RowDefinitions="Auto, Auto, Auto">
|
<TextBlock
|
||||||
<iri:IrihiLogo
|
HorizontalAlignment="Center"
|
||||||
Grid.Row="0"
|
FontSize="14"
|
||||||
Grid.Column="0"
|
Text="Aesthetic Evolution of Productivity" />
|
||||||
Width="64"
|
</StackPanel>
|
||||||
Margin="0,0,16,0"
|
</Grid>
|
||||||
Fill="{DynamicResource SemiGrey5}" />
|
|
||||||
<StackPanel Grid.Row="0" Grid.Column="1">
|
|
||||||
<TextBlock
|
|
||||||
Classes="H2"
|
|
||||||
Text="铱泓科技"
|
|
||||||
Theme="{DynamicResource TitleTextBlock}" />
|
|
||||||
<TextBlock FontWeight="Bold" Text="IRIHI Technology" />
|
|
||||||
</StackPanel>
|
|
||||||
<ProgressBar Grid.Row="1" Grid.ColumnSpan="2" Value="{Binding Progress}" Margin="0 16 0 0"/>
|
|
||||||
<StackPanel
|
|
||||||
Grid.Row="2"
|
|
||||||
Grid.Column="0"
|
|
||||||
Grid.ColumnSpan="2">
|
|
||||||
<TextBlock
|
|
||||||
Margin="0,12,0,0"
|
|
||||||
HorizontalAlignment="Center"
|
|
||||||
FontSize="14"
|
|
||||||
Text="聚焦生产力的美学进化" />
|
|
||||||
<TextBlock
|
|
||||||
HorizontalAlignment="Center"
|
|
||||||
FontSize="14"
|
|
||||||
Text="Aesthetic Evolution of Productivity" />
|
|
||||||
</StackPanel>
|
|
||||||
</Grid>
|
|
||||||
</u:SplashWindow>
|
</u:SplashWindow>
|
||||||
|
|||||||
@@ -14,11 +14,15 @@ public partial class MvvmSplashWindow : SplashWindow
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<Window> CreateNextWindow()
|
protected override async Task<Window?> CreateNextWindow()
|
||||||
{
|
{
|
||||||
return new MainWindow()
|
if (this.DialogResult is true)
|
||||||
{
|
{
|
||||||
DataContext = new MainViewViewModel()
|
return new MainWindow()
|
||||||
};
|
{
|
||||||
|
DataContext = new MainViewViewModel()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,8 @@ public abstract class SplashWindow: Window
|
|||||||
|
|
||||||
private void OnContextRequestClose(object? sender, object? args)
|
private void OnContextRequestClose(object? sender, object? args)
|
||||||
{
|
{
|
||||||
Close(args);
|
DialogResult = args;
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLoaded(RoutedEventArgs e)
|
protected override void OnLoaded(RoutedEventArgs e)
|
||||||
@@ -47,8 +48,10 @@ public abstract class SplashWindow: Window
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected object? DialogResult { get; private set; }
|
||||||
|
|
||||||
protected virtual Task<bool> CanClose() => Task.FromResult(true);
|
protected virtual Task<bool> CanClose() => Task.FromResult(true);
|
||||||
protected abstract Task<Window> CreateNextWindow();
|
protected abstract Task<Window?> CreateNextWindow();
|
||||||
|
|
||||||
private bool _canClose;
|
private bool _canClose;
|
||||||
|
|
||||||
@@ -62,16 +65,17 @@ public abstract class SplashWindow: Window
|
|||||||
if (_canClose)
|
if (_canClose)
|
||||||
{
|
{
|
||||||
var nextWindow = await CreateNextWindow();
|
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;
|
lifetime.MainWindow = nextWindow;
|
||||||
}
|
}
|
||||||
nextWindow.Show();
|
nextWindow?.Show();
|
||||||
Close();
|
Close();
|
||||||
if (DataContext is IDialogContext idc)
|
if (DataContext is IDialogContext idc)
|
||||||
{
|
{
|
||||||
idc.Close();
|
// unregister in advance in case developer try to raise event again.
|
||||||
idc.RequestClose -= OnContextRequestClose;
|
idc.RequestClose -= OnContextRequestClose;
|
||||||
|
idc.Close();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user