question

AndrewNasonov-0450 avatar image
0 Votes"
AndrewNasonov-0450 asked AndrewNasonov-0450 commented

WPF rendering issue on any machine

Please follow this steps to catch problem on your machine. Please, help me resolve it.

  1. Create empty WPF project.

  2. Use property CacheMode="BitmapCache" in MainWindow's Grid;

  3. Show MainWindow on start application, then hide it. Show new any Window, for example new MainWindow. You can use a code below.

  4. 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-wpfdotnet-wpf-xaml
· 13
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AndrewNasonov-0450
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();
             }
         }
0 Votes 0 ·

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.

0 Votes 0 ·

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.

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 AndrewNasonov-0450 ·

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.

0 Votes 0 ·
Show more comments

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.

0 Votes 0 ·

Please, can anyone help me? Is it so hard to reproduce that issue?

0 Votes 0 ·

@AndrewNasonov-0450
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.

0 Votes 0 ·

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.

0 Votes 0 ·

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.

0 Votes 0 ·

How can I resolve that issue without disabling cache mode or set RenderMode.SoftwareOnly to application?

0 Votes 0 ·

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?

0 Votes 0 ·

0 Answers