WPF rendering issue on any machine
Please follow this steps to catch problem on your machine. Please, help me resolve it.
- Create empty WPF project.
- Use property CacheMode="BitmapCache" in MainWindow's Grid;
- Show MainWindow on start application, then hide it. Show new any Window, for example new MainWindow. You can use a code below.
- Press Ctrl + Alt + Del or Win + L and try to interact with showed window (resize, minimize) it should be broken now. var window1 = new MainWindow();
window1.Show();
await Task.Delay(1000);
window1.Hide();
var window2 = new MainWindow();
window2.Show();
Tested on Windows 10, different video cards and PCs. On each PC the issue exist.
I've project where you can try to get the same issue: https://github.com/Erapchu/GhostWindows
Windows Presentation Foundation
XAML
-
DaisyTian-1203 11,626 Reputation points
2021-03-01T04:52:30.77+00:00 @Andrey Nasonov
I made a test demo like you said, but I can't reproduce your error. Below is my info for demo, could you point out which step I missed?
My project targets .Net framework4.8 , and its MainWindow.Xaml code is:<Grid> <Grid.CacheMode> <BitmapCache/> </Grid.CacheMode> <Label FontSize="35" Content="WPF MainWindow"></Label> </Grid>
Add
StateChanged="Window_StateChanged"
for the MainWindow.Xaml, then implement the event in cs code as:private async void Window_StateChanged(object sender, EventArgs e) { if (WindowState == WindowState.Minimized) { var window1 = new MainWindow(); window1.Show(); await Task.Delay(1000); window1.Hide(); var window2 = new MainWindow(); window2.Show(); } }
-
Andrey Nasonov 21 Reputation points
2021-03-01T04:56:49.67+00:00 Hello!
Please place code from event to App.xaml.cs OnStartup overrided method. Not when window state changed. All windows will be created from startup event, additionally remove startup Uri from app.xaml. -
Andrey Nasonov 21 Reputation points
2021-03-01T04:58:10.18+00:00 Hello!
Please place code from event to App.xaml.cs OnStartup overrided method. Not when window state changed. All windows will be created from startup event, additionally remove startup Uri from app.xaml. -
Andrey Nasonov 21 Reputation points
2021-03-01T06:02:17.93+00:00 The main goal is press Ctrl + Alt + Del or Win + L (probably those actions stop rendering WPF windows) when first shown window is hidden and those windows should contains CacheMode property set to BitmapCache on any UI element.
Just BitmapCache broke any WPF window if used. -
Andrey Nasonov 21 Reputation points
2021-03-01T07:55:33.247+00:00 I've project where you can try to get the same issue: https://github.com/Erapchu/GhostWindows
After second window is shown please tap on Ctrl + Alt + Del OR Win + L, then try to interact with shown window. This window will not be rendered while first window is hidden. This window works as expected, but you can't see it's content. You can try to minimize/maximize window or change it size. When first window will be show - the second independent window will continue render.
-
Viorel 118K Reputation points
2021-03-01T12:52:42.76+00:00 As a workaround, if window1 is not needed, you can try executing window1.Close() after window2.Show(). This will also solve the problem of application still running in background even after closing the visible second window.
-
Andrey Nasonov 21 Reputation points
2021-03-01T17:28:01.71+00:00 It’s not a workaround for me. I need to re-show hidden window in future again. Additionally I know that if you change width or height of hidden window that invoke redraw, it will invoke redraw on all other windows and normalize their state.
I think that issue internally in WPF, with bitmap caching. -
Andrey Nasonov 21 Reputation points
2021-03-01T17:34:49.727+00:00 Sorry for one more comment, but I want to say one more thing. If I’m disable hardware acceleration for WPF app (only software) - issue is vanished. It’s not a workaround again, because sometimes a lot of graphic may lagging.
Only one solution is correct - don’t use caching at all. But sometimes I need it and sometimes I need to tap ctrl alt del or lock windows session -
Andrey Nasonov 21 Reputation points
2021-03-09T01:00:47.433+00:00 Please, can anyone help me? Is it so hard to reproduce that issue?
-
DaisyTian-1203 11,626 Reputation points
2021-03-10T01:46:55.67+00:00 @Andrey Nasonov
I can reproduce your problem based on your description and demo, could you tell me what do you want to do with the hidden window1? If you have done an operation on Windows 2, Windows 1 is no longer the latest data. -
Andrey Nasonov 21 Reputation points
2021-03-10T01:53:29.073+00:00 The window always works while the process is running. It's just hidden and I show that window when user click on a button. This is a part of other big project. And full reload window is costly operation when user need to just open a window to see information.
-
Andrey Nasonov 21 Reputation points
2021-03-10T02:04:19.3+00:00 Let's look at it from the other side.
I can call Hide() for any window. I'm using BitmapCache to improve performance in WPF windows and no matter for what component it will be applied - to root grid or just to only one button inside grid. Somewhere. And finally I meet with a problem. -
Andrey Nasonov 21 Reputation points
2021-03-12T01:48:27.053+00:00 How can I resolve that issue without disabling cache mode or set RenderMode.SoftwareOnly to application?
-
Andrey Nasonov 21 Reputation points
2021-03-24T08:02:36.6+00:00 Seems like it's a bug of WPF.
I just try to resolve it, but totally can't. When we using BitmapCache, it's just suspend rendering of all windows when first shown WPF window is hidden and tap Ctrl + Alt + Del or lock windows user session Win + L, while first WPF window will not be shown or updated somehow.
Can I use different BitmapCache implementation? -
David Šeda 5 Reputation points
2024-03-19T14:02:34.6233333+00:00 Hello,
I can't believe I've found exactly same problem I am currently solving. Have you ever found a solution for this?
Just asking in advance, I will try to resolve this too, but need to find more time for it and will update if anything found :)
Thanks and have a nice day
-
Andrey Nasonov 21 Reputation points
2024-03-19T14:06:56.9633333+00:00 Just close all WPF windows, never hide it.
-
David Šeda 5 Reputation points
2024-03-20T09:34:05.7333333+00:00 Actually found out this thread of yours on MaterialDesign which is exactly what the problem was: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/2377
Thanks for your continued effort in this problem! Helped me a ton
Sign in to comment