dotMorten / WinUIEx

WinUI Extensions
https://dotmorten.github.io/WinUIEx
MIT License
615 stars 40 forks source link

Splash Screen Request Feature to Defer Activating Window #69

Closed jrovny closed 1 year ago

jrovny commented 2 years ago

Hi dotMorten,

First, we greatly appreciate the SplashScreen feature of this project.

We wanted to know if it's possible to suppress Activating the window from the splash screen. There's some styling that occurs in the window and when the window is activated too early some of that styling causes considerable flicker.

Perhaps there can be a flag to indicate whether to Activate the window?

private async void Content_Loaded(object sender, RoutedEventArgs e)
{
    if (IsAlwaysOnTop)
        this.SetIsAlwaysOnTop(true);
    else
        WindowExtensions.SetForegroundWindow(this);
    double h = Height;
    double w = Width;
    if (Content is FrameworkElement f)
    {
        if (double.IsNaN(Width) && f.DesiredSize.Width > 0)
            w = f.DesiredSize.Width;
        if (double.IsNaN(Height) && f.DesiredSize.Height > 0)
            h = f.DesiredSize.Height;
    }
    if (double.IsNaN(w))
        w = 640;
    if (double.IsNaN(h))
        h = 480;

    this.CenterOnScreen(w, h);
    await OnLoading();
    if (_windowType != null)
        _window = Activator.CreateInstance(_windowType) as Window;
    _window?.Activate(); // Is it possible to suppress / defer this?
    this.Close();
    _window?.SetForegroundWindow();
    Completed?.Invoke(this, _window);
    _window = null;
}
jrovny commented 2 years ago

I'm thinking a good workaround for us it to instantiate a window ahead of time and utilize the first constructor of the SplashScreen that takes in an instanced window. That way the styling can be applied while the window is invisible. Only issue now is that it doesn't start the window out as maximized, but we can do that in the main app.xaml.cs file.

dotMorten commented 2 years ago

I'm not quite following the issue here (do you have a repro?). If you don't activate the window, the window won't start loading and rendering its contents. The splashscreen isn't that special - it's just one window with a few fixed size settings showing before opening the next one, so you could just create any window and use as a splashscreen.

jrovny commented 2 years ago

True, we tried that option (our own version of the splash screen) and that worked as well. I think we're good to close this issue.

Thank you!