Splash screen for application startup #11083
Replies: 8 comments 18 replies
-
Relates to #4155 |
Beta Was this translation helpful? Give feedback.
-
Relates also to #2674 |
Beta Was this translation helpful? Give feedback.
-
I think it would be great addition to the https://github.com/AvaloniaUI/Avalonia.Samples |
Beta Was this translation helpful? Give feedback.
-
Hello @llfab |
Beta Was this translation helpful? Give feedback.
-
@maxkatz6 @timunie
Fortunately, I have found a solution for splash without async as follows: public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
// Open splash screen as early as possible
_splashScreenWindow = new SplashScreenWindow();
desktopLifetime.MainWindow = _splashScreenWindow;
// delegate actual application start to when UI thread has time again
Dispatcher.UIThread.Post(() => CompleteApplicationStart(), DispatcherPriority.Background);
}
base.OnFrameworkInitializationCompleted();
}
public void CompleteApplicationStart()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
// Start the system which is taking some seconds
_pixrBunionSystem = new PixrNpcSystem(startupParameters);
_pixrBunionSystem.Init();
// create the window with its data context
_mainWindowViewModel = new MainWindowViewModel();
_mainWindow = new MainWindow()
{
DataContext = _mainWindowViewModel,
};
desktopLifetime.MainWindow = _mainWindow;
// Show main window to avoid framework shutdown when closing splash screen
_mainWindow.Show();
// Finally, close the splash screen
_splashScreenWindow.Close();
}
} So this does not use an other thread. Just before leaving the Let me know what you think... |
Beta Was this translation helpful? Give feedback.
-
Hi, I went a similar but simpler (to me) approach here. However Im also having issues (more on this will follow).
The MainWindow/ViewModel acts as a content presenter, so the constructor displays a loading screen as its content
Then the Async Init() function who does the heavy lifting is called
This works fine on windows desktop. However, for some reason, this does not work on Linux desktop (Debian), nor does it work in WSL, the "Loading" view is never shown and the app just hangs for a bit and jumps straight to the mainwindowviewmodel. So I tried your way of doing this, but I get the same results, works fine on Windows but somehow not on WSL or a full Debian install. Am I doing something wrong that would cause this ? |
Beta Was this translation helpful? Give feedback.
-
So just to understand. - the window is shown immediately- but no loading content- hangs- final content is shown???To be honest I have not tried it on Linux. I have experienced diffs in Windowing behavior in the past but not with view content. I will try that some time on Linux...
|
Beta Was this translation helpful? Give feedback.
-
I always achieve this by a stupid way:
Make a splash screen with usercontrol and set it as content of a ContentPresenter in MainWindow. After the splash screen is finished, set the content of ContentPresenter to the main page (also make it as usercontrol) of your program. All running in the same window without creating a new one. I am not sure whether it is what you need. |
Beta Was this translation helpful? Give feedback.
-
Because I had not found a working description in the past discussions, I found this sample application for a working splash screen extremely useful. Maybe that helps others as well.
https://github.com/kivarsen/AvaloniaSplashScreenDemo
Beta Was this translation helpful? Give feedback.
All reactions