✅ Creating An Accurate Loading Screen Avalonia
<Window 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:vm="using:MeksMathGame.ViewModels"
mc:Ignorable="d"
x:Class="MeksMathGame.Views.SplashScreenView"
x:DataType="vm:SplashScreenViewModel"
Title="SplashScreenView"
Width="220"
Height="130"
SystemDecorations="None"
WindowStartupLocation="CenterScreen"
TransparencyLevelHint="Transparent"
TransparencyBackgroundFallback="Transparent">
<Design.DataContext>
<vm:SplashScreenViewModel />
</Design.DataContext>
<Border Background="#fff" CornerRadius="10" Padding="10">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="5">
<Image Source="/Assets/avalonia-logo.ico" Width="50" Height="50" />
<TextBlock Text="{Binding StartUpMessage}" />
<Button HorizontalAlignment="Center" Command="{Binding Cancel}" Content="Cancel" />
</StackPanel>
</Border>
</Window><Window 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:vm="using:MeksMathGame.ViewModels"
mc:Ignorable="d"
x:Class="MeksMathGame.Views.SplashScreenView"
x:DataType="vm:SplashScreenViewModel"
Title="SplashScreenView"
Width="220"
Height="130"
SystemDecorations="None"
WindowStartupLocation="CenterScreen"
TransparencyLevelHint="Transparent"
TransparencyBackgroundFallback="Transparent">
<Design.DataContext>
<vm:SplashScreenViewModel />
</Design.DataContext>
<Border Background="#fff" CornerRadius="10" Padding="10">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="5">
<Image Source="/Assets/avalonia-logo.ico" Width="50" Height="50" />
<TextBlock Text="{Binding StartUpMessage}" />
<Button HorizontalAlignment="Center" Command="{Binding Cancel}" Content="Cancel" />
</StackPanel>
</Border>
</Window>using ReactiveUI;
using System.Threading;
namespace MeksMathGame.ViewModels;
internal class SplashScreenViewModel : ViewModelBase
{
private string _startUpMessage = "Application Is Loading. . .";
private CancellationTokenSource _cts = new CancellationTokenSource();
public CancellationToken cancellationToken => _cts.Token;
public void Cancel()
{
_cts.Cancel();
}
public string StartUpMessage
{
get => _startUpMessage;
set => this.RaiseAndSetIfChanged(ref _startUpMessage, value);
}
}using ReactiveUI;
using System.Threading;
namespace MeksMathGame.ViewModels;
internal class SplashScreenViewModel : ViewModelBase
{
private string _startUpMessage = "Application Is Loading. . .";
private CancellationTokenSource _cts = new CancellationTokenSource();
public CancellationToken cancellationToken => _cts.Token;
public void Cancel()
{
_cts.Cancel();
}
public string StartUpMessage
{
get => _startUpMessage;
set => this.RaiseAndSetIfChanged(ref _startUpMessage, value);
}
}