feat: add splash window.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Data.Core.Plugins;
|
using Avalonia.Data.Core.Plugins;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
@@ -21,10 +22,7 @@ public partial class App : Application
|
|||||||
// Line below is needed to remove Avalonia data validation.
|
// Line below is needed to remove Avalonia data validation.
|
||||||
// Without this line you will get duplicate validations from both Avalonia and CT
|
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||||
BindingPlugins.DataValidators.RemoveAt(0);
|
BindingPlugins.DataValidators.RemoveAt(0);
|
||||||
desktop.MainWindow = new MainWindow
|
desktop.MainWindow = new MainSplashWindow();
|
||||||
{
|
|
||||||
DataContext = new MainWindowViewModel(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
|
|||||||
12
demo/Sandbox/Views/MainSplashWindow.axaml
Normal file
12
demo/Sandbox/Views/MainSplashWindow.axaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<u:SplashWindow xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800"
|
||||||
|
d:DesignHeight="450"
|
||||||
|
CountDown="0:0:2"
|
||||||
|
x:Class="Sandbox.Views.MainSplashWindow"
|
||||||
|
Title="MainSplashWindow">
|
||||||
|
Welcome to Avalonia Splash Window!
|
||||||
|
</u:SplashWindow>
|
||||||
27
demo/Sandbox/Views/MainSplashWindow.axaml.cs
Normal file
27
demo/Sandbox/Views/MainSplashWindow.axaml.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Timers;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using Sandbox.ViewModels;
|
||||||
|
using Ursa.Controls;
|
||||||
|
|
||||||
|
namespace Sandbox.Views;
|
||||||
|
|
||||||
|
public partial class MainSplashWindow : SplashWindow
|
||||||
|
{
|
||||||
|
public MainSplashWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<Window> CreateNextWindow()
|
||||||
|
{
|
||||||
|
return new MainWindow()
|
||||||
|
{
|
||||||
|
DataContext = new MainWindowViewModel()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,10 +18,7 @@ public partial class App : Application
|
|||||||
{
|
{
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
{
|
{
|
||||||
desktop.MainWindow = new MainWindow()
|
desktop.MainWindow = new MainSplashWindow();
|
||||||
{
|
|
||||||
DataContext = new MainViewViewModel(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
|
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
|
||||||
{
|
{
|
||||||
|
|||||||
54
demo/Ursa.Demo/Views/MainSplashWindow.axaml
Normal file
54
demo/Ursa.Demo/Views/MainSplashWindow.axaml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<u:SplashWindow
|
||||||
|
x:Class="Ursa.Demo.Views.MainSplashWindow"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:iri="https://irihi.tech/shared"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
|
Title="MainSplashWindow"
|
||||||
|
Width="400"
|
||||||
|
Height="400"
|
||||||
|
d:DesignHeight="450"
|
||||||
|
d:DesignWidth="800"
|
||||||
|
CountDown="0:0:3"
|
||||||
|
ExtendClientAreaChromeHints="NoChrome"
|
||||||
|
ExtendClientAreaTitleBarHeightHint="0"
|
||||||
|
ExtendClientAreaToDecorationsHint="True"
|
||||||
|
SystemDecorations="None"
|
||||||
|
WindowStartupLocation="CenterScreen"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<Grid
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
ColumnDefinitions="Auto, Auto"
|
||||||
|
RowDefinitions="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>
|
||||||
|
<StackPanel
|
||||||
|
Grid.Row="1"
|
||||||
|
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>
|
||||||
24
demo/Ursa.Demo/Views/MainSplashWindow.axaml.cs
Normal file
24
demo/Ursa.Demo/Views/MainSplashWindow.axaml.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Ursa.Controls;
|
||||||
|
using Ursa.Demo.ViewModels;
|
||||||
|
|
||||||
|
namespace Ursa.Demo.Views;
|
||||||
|
|
||||||
|
public partial class MainSplashWindow : SplashWindow
|
||||||
|
{
|
||||||
|
public MainSplashWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<Window> CreateNextWindow()
|
||||||
|
{
|
||||||
|
return new MainWindow()
|
||||||
|
{
|
||||||
|
DataContext = new MainViewViewModel()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
x:CompileBindings="True"
|
x:CompileBindings="True"
|
||||||
x:DataType="viewModels:MainWindowViewModel"
|
x:DataType="viewModels:MainWindowViewModel"
|
||||||
|
WindowStartupLocation="CenterScreen"
|
||||||
Icon="/Assets/Ursa.ico"
|
Icon="/Assets/Ursa.ico"
|
||||||
IsFullScreenButtonVisible="{OnPlatform True, macOS=False}"
|
IsFullScreenButtonVisible="{OnPlatform True, macOS=False}"
|
||||||
IsManagedResizerVisible="{OnPlatform False, Linux=True}"
|
IsManagedResizerVisible="{OnPlatform False, Linux=True}"
|
||||||
|
|||||||
56
src/Ursa/Windows/SplashWindow.cs
Normal file
56
src/Ursa/Windows/SplashWindow.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public abstract class SplashWindow: Window
|
||||||
|
{
|
||||||
|
public static readonly StyledProperty<TimeSpan?> CountDownProperty = AvaloniaProperty.Register<SplashWindow, TimeSpan?>(
|
||||||
|
nameof(CountDown));
|
||||||
|
|
||||||
|
public TimeSpan? CountDown
|
||||||
|
{
|
||||||
|
get => GetValue(CountDownProperty);
|
||||||
|
set => SetValue(CountDownProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnLoaded(RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnLoaded(e);
|
||||||
|
if (CountDown != null && CountDown != TimeSpan.Zero)
|
||||||
|
{
|
||||||
|
DispatcherTimer.RunOnce(Close, CountDown.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual Task<bool> CanClose() => Task.FromResult(true);
|
||||||
|
protected abstract Task<Window> CreateNextWindow();
|
||||||
|
|
||||||
|
private bool _canClose;
|
||||||
|
|
||||||
|
protected override sealed async void OnClosing(WindowClosingEventArgs e)
|
||||||
|
{
|
||||||
|
VerifyAccess();
|
||||||
|
if (!_canClose)
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
_canClose = await CanClose();
|
||||||
|
if (_canClose)
|
||||||
|
{
|
||||||
|
var nextWindow = await CreateNextWindow();
|
||||||
|
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
|
||||||
|
{
|
||||||
|
lifetime.MainWindow = nextWindow;
|
||||||
|
}
|
||||||
|
nextWindow.Show();
|
||||||
|
Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base.OnClosing(e);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user