microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

[WinUI][dotnet8] - New window blinks when loading a content.

Open rodirigos opened this issue 11 months ago • 27 comments

Describe the bug

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. It also occurs using MAUI.

Steps to reproduce the bug

1 - Create multiple windows with some content and an alternative background color.

Expected behavior

It should open like in dotnet7, appearing all the window with a rendered content. (not a flickering before opening).

Screenshots

Image

NuGet package version

None

Windows version

No response

Additional context

No response

rodirigos avatar Dec 27 '24 19:12 rodirigos

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.

danielancines avatar Dec 27 '24 20:12 danielancines

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

lfmouradasilva avatar Dec 27 '24 21:12 lfmouradasilva

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.

fpedrolucas95 avatar Dec 27 '24 22:12 fpedrolucas95

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.

Elwilton avatar Dec 28 '24 00:12 Elwilton

Similar problems exist when using the C++ language. Image

lgztx96 avatar Dec 28 '24 04:12 lgztx96

I encountered the same problem in some tests I did while migrating the .NET version. Because of that, I had to pause the migration.

MasterOliver21 avatar Dec 30 '24 11:12 MasterOliver21

Here's some example using WinUI https://github.com/rodirigos/NewWindowTest There's already an example in Maui with a more appealing issue

rodirigos avatar Dec 30 '24 11:12 rodirigos

@rodirigos You can set the RequestedTheme property of the StackPanel (the window content) to ElementTheme.Dark if you want the window background color to be black.

lhak avatar Jan 01 '25 20:01 lhak

@rodirigos You can set the RequestedTheme property of the StackPanel (the window content) to ElementTheme.Dark if you want the window background color to be black.

Yes, the window background was black and behavior is the same, but less visible.

Image

danielancines avatar Jan 02 '25 11:01 danielancines

@rodirigos You can set the RequestedTheme property of the StackPanel (the window content) to ElementTheme.Dark if you want the window background color to be black.

Same behavior. Only changed the color to show the delay. As you can see in the example above, the labels inside the content still have the same issue.

rodirigos avatar Jan 02 '25 11:01 rodirigos

@rodirigos You can set the RequestedTheme property of the StackPanel (the window content) to ElementTheme.Dark if you want the window background color to be black.

Same behavior. Only changed the color to show the delay. As you can see in the example above, the labels inside the content still have the same issue.

I have the same problem in .NET 7.0 (Windows 10 22H2, Windows App SDK 1.6.241114003, slow PC) Test with your sample (I just changed colors, size, ...) :

Image

castorix avatar Jan 02 '25 12:01 castorix

One issue here is that all windows are created and shown on the UI thread, so there is never a chance for the content to render until all windows are visible. Moving the call of window.Activate() to a low priority dispatcher call with DispatcherQueue.TryEnqueue might improve things.

However, in my experience, some delay between the window background and the XAML content showing cannot currently be avoided. I guess a fix would require more work in winui to pre-render the content before the window is visible.

lhak avatar Jan 02 '25 16:01 lhak

One issue here is that all windows are created and shown on the UI thread, so there is never a chance for the content to render until all windows are visible. Moving the call of window.Activate() to a low priority dispatcher call with DispatcherQueue.TryEnqueue might improve things.

However, in my experience, some delay between the window background and the XAML content showing cannot currently be avoided. I guess a fix would require more work in winui to pre-render the content before the window is visible.

Thanks for the advice, but the problem is that @lgztx96 described previously, one window, delay to load the content. This behavior was noticed after update a .net Maui application to .net 8 in this issue: https://github.com/dotnet/maui/issues/26849#issuecomment-2566178140

https://github.com/microsoft/microsoft-ui-xaml/issues/10259#issuecomment-2564163096

danielancines avatar Jan 02 '25 18:01 danielancines

One issue here is that all windows are created and shown on the UI thread, so there is never a chance for the content to render until all windows are visible. Moving the call of window.Activate() to a low priority dispatcher call with DispatcherQueue.TryEnqueue might improve things. However, in my experience, some delay between the window background and the XAML content showing cannot currently be avoided. I guess a fix would require more work in winui to pre-render the content before the window is visible.

Thanks for the advice, but the problem is that @lgztx96 described previously, one window, delay to load the content. This behavior was noticed after update a .net Maui application to .net 8 in this issue: dotnet/maui#26849 (comment)

#10259 (comment)

I have not noticed any major changes of this delay using different .net and winui versions. However, I can confirm that the maui version from @rodirigos is drastically slower than the winui one. So I guess the regression is caused by changes in the maui code.

lhak avatar Jan 03 '25 18:01 lhak

Any update about this issue?

fpedrolucas95 avatar Jan 14 '25 12:01 fpedrolucas95

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?

Elwilton avatar Jan 14 '25 12:01 Elwilton

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.

lfmouradasilva avatar Jan 17 '25 08:01 lfmouradasilva

Any update about this issue?

fpedrolucas95 avatar Jan 25 '25 01:01 fpedrolucas95

Hi guys, .net Maui team, at issue Maui Issue said the issue is on WinUi and tell us to get some help in this issue, could you help us?

This issue is blocking our app with 1k+ users to upgrade to .net 8 and forcing us to run in .net 7 (out of support).

danielancines avatar Jan 28 '25 20:01 danielancines

This looks very similar to MSFT:53079949 internally. That internal thread is a little more narrow - seems like there's a single frame when SW_SHOW'ing a window where the background of the HWND is black, before any xmal gets painted into it.

Maybe the two are different root causes, but they do feel similar.

zadjii-msft avatar Feb 12 '25 20:02 zadjii-msft

@zadjii-msft is there any workaround to avoid this behavior?

danielancines avatar Feb 24 '25 19:02 danielancines

Hi @rodirigos , can you please us by providing the repro project, so that to help us in further investigation here?

snigdha011997 avatar Mar 19 '25 10:03 snigdha011997

Hi. The project can be found in this link https://github.com/rodirigos/NewWindowTest I suggest to take a look on MAUI since the issue is more appealing in that plataform,

rodirigos avatar Mar 21 '25 19:03 rodirigos

By making the windows layered (alpha 0 then 255 on first CompositionTarget.Rendering frame, it is better :

Image

castorix avatar Jun 02 '25 09:06 castorix

Hey do you have any static fonction to make this please ? This seems to be enough for most apps. Even AI struggles to make as functional as your video.

By making the windows layered (alpha 0 then 255 on first CompositionTarget.Rendering frame, it is better :

Image

ConstantinCOSTEA avatar Sep 25 '25 21:09 ConstantinCOSTEA

Hey do you have any static fonction to make this please ? This seems to be enough for most apps. Even AI struggles to make as functional as your video.

In fact, I just tested again, but when I create bigger windows than in the GIF, the blinking can still be seen 🤔 So it seems better, but not a good solution...

castorix avatar Oct 01 '25 07:10 castorix