C
C#14mo ago
Mekasu0124

✅ 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);
}
}
I'm starting my application off with a loading screen that shows on launch. How can I make this loading screen accurate like what you see on other applications. Loading resources, applying styles, etc.
11 Replies
JakenVeina
JakenVeina14mo ago
in Avalonia, you probably can't also, the truth is that loading screens like that can often be fake it's relatively common to make loading screens or progress bars that aren't backed up by any real meaning, they're just there to make the user feel like progress is being made for Avalonia, you'd have to hook into their systems for loading things which is really done mostly by the framework so, you could look at .NET's Assembly Loading system, and see if there's places you could hook into the load process but then you'd still have trouble recognizing what your "completion" state is, to derive progress from that this might be useful
Mekasu0124
Mekasu0124OP14mo ago
if it's going to be a lot of trouble to do something like that especially if the framework already handles most of it and the completion state is likely to not exist, then I'll just make a different type of one. Currently, I have it setup to check for an update for the application, and if one exists then display two additional buttons
JakenVeina
JakenVeina14mo ago
if you can pre-build an accurate profile of all the assemblies that get loaded by your application, and bake that in, you could maybe go off of that the other concern is how much of the loading takes place before Avalonia even has a chance to DISPLAY anything
Mekasu0124
Mekasu0124OP14mo ago
yea see all of that is just a bit too much trouble imo. I'll just make my own version of one
JakenVeina
JakenVeina14mo ago
if you really wanted to do it properly, you'd probably need to code up a little splash window on startup that doesn't even USE Avalonia realistically, yeah, it's probably doable to make something reasonable, but is it worth the effort?
Mekasu0124
Mekasu0124OP14mo ago
honestly, after reading all of that you just explained, no lol
JakenVeina
JakenVeina14mo ago
also this, if you haven't read it
JakenVeina
JakenVeina14mo ago
GitHub
Splash Screen · Issue #2674 · AvaloniaUI/Avalonia
I would like my application to open with a splash screen of a .ico or image file for a few seconds, then open to my MainWindow. Is there a way to do this yet, perhaps similar to how WPF handles spl...
JakenVeina
JakenVeina14mo ago
sorry to disappoint
Mekasu0124
Mekasu0124OP14mo ago
nah you're fine 🙂 thank you for your help!
Want results from more Discord servers?
Add your server