Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAUI][dotnet8][Windows] - A blink occurs when opening a new window #26849

Open
rodirigos opened this issue Dec 27, 2024 · 21 comments
Open

[MAUI][dotnet8][Windows] - A blink occurs when opening a new window #26849

rodirigos opened this issue Dec 27, 2024 · 21 comments
Labels
area-controls-window Window i/regression This issue described a confirmed regression on a currently supported version partner/winui WinUI / Project Reunion platform/windows 🪟 regressed-in-9.0.0 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@rodirigos
Copy link

rodirigos commented Dec 27, 2024

Description

In .NET 7, windows wait to render the content before opening. In .NET 8 and later, an unintended flicker occurs while loading this content. This flicker comes with a default background.

Image

Steps to Reproduce

1 - Create multiple windows using Application.Current.OpenWindow()
2 - See the blink before opening the content

To check a reprodution, just open this application here
https://github.com/rodirigos/MauiBlinkingTest

It is also happening in Winui directly, but the blink is way faster
microsoft/microsoft-ui-xaml#10259

Link to public reproduction project repository

https://github.com/rodirigos/MauiBlinkingTest
It is also happening directly in WinUI
https://github.com/rodirigos/NewWindowTest

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.101

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

@rodirigos rodirigos added the t/bug Something isn't working label Dec 27, 2024
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@danielancines
Copy link

I have a MDI large application for a Bank in .net Maui, using Pinvoke.SetParent and not able to migrate to .net 8 and 9 because of this behavior.

@lfmouradasilva
Copy link

Same issue here. This is a breaking change, and it’s blocking me from updating my application.

@fpedrolucas95
Copy link

I'm also experiencing this flickering issue in a .NET Maui desktop application. This is a significant blocker for updating to .NET 8 and 9, as it creates a poor user experience.

@Elwilton
Copy link

I’m facing the same issue. I’m trying to migrate from .NET 7 to .NET 8 and having problems with the presentation of new screens.

@jfversluis jfversluis added s/needs-repro Attach a solution or code which reproduces the issue area-controls-window Window potential-regression This issue described a possible regression on a currently supported version., verification pending labels Dec 28, 2024
@rodirigos
Copy link
Author

rodirigos commented Dec 28, 2024

In this example, you can open multiple windows by just clicking the button in the default test application.
https://github.com/rodirigos/MauiBlinkingTest

It is really simple to reproduce the issue. It will open multiple windows and you can check the behavior since the pages were in another color.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Dec 28, 2024
@RoiChen001
Copy link

@rodirigos The repository you provided is private and we don't have access to it. Could you add it to the public repository or recreate a new sample project for us? Looking forward to your reply!

@rodirigos
Copy link
Author

Already changed the visibility!

@RoiChen001 RoiChen001 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed i/regression This issue described a confirmed regression on a currently supported version and removed potential-regression This issue described a possible regression on a currently supported version., verification pending labels Dec 31, 2024
@RoiChen001
Copy link

This issue can be reproduced at the latest 17.13.0 Preview 2.1(9.0.21 & 8.0.100), but it worked fine at .NET7.

@danielancines
Copy link

danielancines commented Jan 3, 2025

Hey guys, any update about this? We finished a large trading application upgrade to dotnet 8, but we cannot move forward because of this situation. Since .net 7 is out of support, my manager is asking me every day about a beta version using dotnet 8.

@mattleibow
Copy link
Member

We updated WinUI in each version of .NET MAUI, so this may be a bug that is in WinUI and due to MAUI loading things at launch it makes it more noticeable.

Did you run as release mode without the debugger attached? Also, can you enable <PublishReadyToRun>true</PublishReadyToRun> when publishing as this does some more AOT compilation.

I wonder if this is just a delay with various hot reload things happening and not actually a release issue. I am sure we pause things at launch to prepare the hot reloads and debuggers.

@mattleibow mattleibow removed the s/needs-attention Issue has more information and needs another look label Jan 6, 2025
@mattleibow mattleibow added this to the Backlog milestone Jan 6, 2025
@mattleibow mattleibow added the s/needs-info Issue needs more info from the author label Jan 6, 2025
@rodirigos
Copy link
Author

Yes. In release version, same behavior.
Image

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 6, 2025
@rodirigos
Copy link
Author

Hi. Any update on this problem?

@danielancines
Copy link

Morning guys, any update on this?

@fpedrolucas95
Copy link

Any update about this issue?

@Elwilton
Copy link

Any update on this issue?
My team and I had to pause a migration because of this issue.
Do we have any predictions for a solution?

@lfmouradasilva
Copy link

Hi team, is there any update on this issue? We’re currently blocked from upgrading our app to the latest .NET version due to this problem. Unfortunately, we’re stuck on an unsupported version with thousands of clients in production, and it’s becoming increasingly critical. Resolving this would allow us to ensure better support and stability for our users. Any guidance or progress on this would be greatly appreciated.

@danielancines
Copy link

@Foda let us know if you need more info about this issue.

@Foda
Copy link
Member

Foda commented Jan 27, 2025

Hello! Since this is a WinUI specific issue, please continue to ask for support in the bug you've created here: microsoft/microsoft-ui-xaml#10259

The delay you're seeing in MAUI is due to the overhead of MAUI itself. We create a few XAML elements (NavigationView, TitleBar) that slightly add to the time it takes for the first render. We set the content of the Window before it's activated, so the delay is (still) caused by WinUI.

Unfortunately, the delay on the WinUI side is caused by the window content no longer being synced to the window itself due to everything being lifted out of DWM. There's an internal issue for WinUI to track this, but I doubt it will be fixed anytime soon.

I'm not sure if it helps at all, but you can force the background that you see to either Black/White by setting the native WinUI Window.Content.RequestedTheme value. Note: you'll also need to manually adjust the titlebar button colors since we do that based on the theme as well.

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp
        .CreateBuilder()
        .UseMauiApp<App>()
        .ConfigureFonts(fonts =>
        {
            ...
        });

    #if WINDOWS
    builder.ConfigureLifecycleEvents(events =>
    {
        // Make sure to add "using Microsoft.Maui.LifecycleEvents;" in the top of the file
        events.AddWindows(windowsLifecycleBuilder =>
        {
            windowsLifecycleBuilder.OnWindowCreated(window =>
            {
                var windowContent = (window.Content as Microsoft.UI.Xaml.FrameworkElement);
                windowContent.RequestedTheme = Microsoft.UI.Xaml.ElementTheme.Dark;

                var panel = (windowContent as Microsoft.UI.Xaml.Controls.Panel);
                foreach (var child in panel.Children)
                {
                    // Set children to light theme
                    var element = (child as Microsoft.UI.Xaml.FrameworkElement);
                    element.RequestedTheme = Microsoft.UI.Xaml.ElementTheme.Light;
                }
            });
        });
    });
    #endif

    return builder.Build();
}

Another option is that you can manually set the color of the window using Win32 APIs. An easy way to do this is by using WindowMessageMonitor from the WinUIEx package. The code to set the background using a custom color looks something like this:

#if WINDOWS

if (msg.MessageId == WM_ERASEBKGND)
{
    RECT rect;
    GetClientRect(wnd.GetWindowHandle(), out rect);

    // Set background to red
    IntPtr hBrush = CreateSolidBrush(System.Drawing.ColorTranslator.ToWin32(
        System.Drawing.Color.FromArgb(255, 255, 0, 0)));

    FillRect(msg.WParam, ref rect, hBrush);
    DeleteObject(hBrush);
    msg.Result = 1;
    msg.Handled = true;
}
...

private static int WM_ERASEBKGND = 0x0014;

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
   public int Left;
   public int Top;
   public int Right;
   public int Bottom;
}

[DllImport("User32", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);

[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool FillRect(IntPtr hdc, [In] ref RECT rect, IntPtr hbrush);

[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateSolidBrush(int crColor);

[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool DeleteObject([In] IntPtr hObject);

#endif

@PureWeen PureWeen modified the milestones: .NET 9 SR5, Backlog Jan 28, 2025
@PureWeen PureWeen added partner/winui WinUI / Project Reunion and removed s/needs-attention Issue has more information and needs another look labels Jan 28, 2025
@danielancines
Copy link

danielancines commented Jan 28, 2025

Thanks @Foda, since is an issue affecting Maui, could you help us to prioritaze this issue? It affects directly user experience for our users and forcing us to hold .net upgrade from 7.

IMHO is a Maui issue too, we need help to fix it.

@danielancines
Copy link

Hi guys, any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-window Window i/regression This issue described a confirmed regression on a currently supported version partner/winui WinUI / Project Reunion platform/windows 🪟 regressed-in-9.0.0 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests