SPLASH SCREEN .NET MAUI MULTIPLATAFORM WINDOWS, ANDROID, IOS, MACOS

FluxuRate 50 Reputation points
2023-08-01T21:31:57.7333333+00:00

Hello, I've been looking for a while now how to make a splashscreen for windows that redirects to the login window when the content is loaded. If you could help me

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,072 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,411 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 81,191 Reputation points Microsoft External Staff
    2023-08-02T02:41:50.2566667+00:00

    Hello,

    ===============Update=============

    how I can remove the upper part where the controls are located to minimize and close the window and the program only on the ScreenPage and on the LoginPage to put my own I attached an image pointing in red to specify

    This feature is added in the github page, please track on this feature :Provide a cross platform API for customizing the TitleBar of desktop apps

    how can I change the size of the window, the splash screen one size, the login screen another, etc.

    You can keep the code in the splash screen, then use the following code to change the window size for login page.

      protected override void OnHandlerChanged()
        {
            base.OnHandlerChanged();
    #if WINDOWS
            Microsoft.UI.Xaml.Window window = (Microsoft.UI.Xaml.Window)App.Current.Windows.First<Window>().Handler.PlatformView;
            IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
            Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
            Microsoft.UI.Windowing.AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
            appWindow.Resize(new Windows.Graphics.SizeInt32(800, 600));
    #endif
        }
    

    you can create a contentpage as a splash screen to load data before navigating to the login page. Here’s an example of how you can achieve this:

    Create a new XAML page for the splash screen (SplashScreenPage.xaml) with an image to display while the data is being loaded.

    In the code-behind file (SplashScreenPage.xaml.cs), use the OnAppearing method to load the necessary data. You can use asynchronous methods to fetch the data from a remote server or perform any other initialization tasks. Once the data loading is complete, navigate to the login page.

    public partial class SplashScreenPage : ContentPage
    {
        public SplashScreenPage()
        {
            InitializeComponent();
        }
        protected override async void OnAppearing()
        {
            base.OnAppearing();
    
           // Load data or perform initialization tasks
            await LoadData();
    
           // Navigate to the login page
            await Navigation.PushModalAsync(new LoginPage());
        }
    
       private async Task LoadData()
        {
            // Perform data loading tasks here
            // For example, fetching data from a remote server
            await Task.Delay(2000); // Simulating a delay here, replace with your actual data loading logic
        }
    }
    

    In your App.xaml.cs file, set the SplashScreen property to the SplashPage you created. This will ensure that the splash screen is displayed when the app starts.

    public App()
        {
            InitializeComponent();
           MainPage = new SplashScreenPage();
        }
    

    For other platforms, if you want to remove the splash screen from MAUI, you can open your .csproj file, remove <MauiSplashScreen> tag.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.