C
C#8mo 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
JakenVeina8mo 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
Mekasu01248mo 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
JakenVeina8mo 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
Mekasu01248mo ago
yea see all of that is just a bit too much trouble imo. I'll just make my own version of one
JakenVeina
JakenVeina8mo 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
Mekasu01248mo ago
honestly, after reading all of that you just explained, no lol
JakenVeina
JakenVeina8mo ago
also this, if you haven't read it
JakenVeina
JakenVeina8mo 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
JakenVeina8mo ago
sorry to disappoint
Mekasu0124
Mekasu01248mo ago
nah you're fine 🙂 thank you for your help!
Want results from more Discord servers?
Add your server
More Posts
❔ Using Linq to Add or Update Score in Highscore List ObjectHi, I created a Highscore object, which consists of an IntValue and StringValue objects. I am trying❔ ✅ whitespaces are doing me dirty```csharp public void Execute() { StringBuilder word = new StringBuilder(); ❔ System.IO.Pipelines cannot complete the readerHey. I'm having `reader.CompleteAsync` throw because it tries to return an empty buffer to the array❔ C# on LinuxHey! New with C#. As a Linux user, I'm very limited by using C# to create apps on my OS using Micros❔ OnActionExecuted exception filter runs before exception is thrown and is never calledI'm having a bit of an issue where I'm following the guide from https://learn.microsoft.com/en-us/as❔ ASP.NET session timeout earlyAlthough the session timeout period is 40 minutes, sometimes (rarely) the session ends before the 40✅ Add tables in a project with EFCoreI already scaffold my DB in the CLI, but i need to add a new table to the project, how should i do t❔ Need help adding a label from a child class to the screen that exists in the parent classSo im coding a board game and the board is its own class, now when the game ends I would like to sho❔ EntityFramework - Need help setting up/creating my first VS Community .NET 2.1 ProjectIm using VS 2019. Usually I use VS Code, because I only use C# for Unity coding. I created a Postgre❔ Entry Binding in custom control doesn't workHi, I'm making simple app in MAUI, tried to create separate control for reusability purpose. My prob