Kinnara / ModernWpf

Modern styles and controls for your WPF applications
MIT License
4.51k stars 449 forks source link

Window content disappears #177

Open milos12345 opened 4 years ago

milos12345 commented 4 years ago

I am using your Fluent WPF example as a base. Main windows is fine, but sometime as additonal window created would be completely blank, and one of the users sent this crash report

System.OverflowException: Arithmetic operation resulted in an overflow.
   at System.Windows.Shell.WindowChromeWorker._HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Shell.WindowChromeWorker._WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

It just has the acrylic effect image and window can still be moved around and closed. When this happens each windows reopening would produce a window like this until program is restarted. I have not found a reliable way to reproduce this.

ShankarBUS commented 4 years ago

This seems to be a problem with FluentWPF, I had this exact same issue while using FluentWPF (only FluentWPF, no other UI libraries) in one of projects. The window would be blank when reopened after a while.

It's too annoying for users. Restarting the app may temporarily fix this issue but it may happen later

So it makes sense to open an issue regarding this on the FluentWPF repo.

milos12345 commented 4 years ago

Thanks, I created it there also https://github.com/sourcechord/FluentWPF/issues/96 Possibly related issue and not sure of the source in ModernWPF or FluentWPF: When using programs with these custom windows over Windows Remote Desktop connection and I disconnect the session, the window will trigger Unloaded event on all controls crashing the program (it may be even triggered twice).

ShankarBUS commented 4 years ago

Hey @milos12345, this seems to be a bug in WPF. It's probably better to submit an issue on WPF's repo.

I have a similar issue on my app. But the window is black instead of blurred (as I'm not using FluentWPF the window is not blurred like yours)

https://github.com/ShankarBUS/ModernFlyouts/issues/12

milos12345 commented 4 years ago

@ShankarBUS but you are using ModernWPF, so I think the bug is in ModernWPF, and another reason I suspect that is because I have removed FluentWPF from my window, and am just using a regular window with ui:ThemeManager.IsThemeAware="True" and I've got a message from a user that it happened again, just the window was completely white. Before adding ModernWPF I've never had that issue in that program (used for 6 years). If it may be relevant, that window has a TabControl

ShankarBUS commented 4 years ago

Both FluentWPF and ModernWpf make use of the WindowChrome feature. That's why I suspect it. We also have a similar stack trace. It could be specific to ModernWpf I don't know 🤷‍♂️

ShankarBUS commented 4 years ago

Mine has a NavigationView it also happens even if don't use UseModernWindowStyle. I'm not sure if ModernWpf causes this.

But let's ask the author.

@Kinnara, any ideas?

milos12345 commented 4 years ago

TabControl is the culprit. It happens after sleep. I have a two of the same windows that are opened from MainWindow, both have just ui:ThemeManager.IsThemeAware="True" One has TabControl.

On the second window, if I delete just the tab control, I can do the sleep-cycle and the content will remain.

Is there a fix for that or will I have to replace tab control with something else?

ShankarBUS commented 4 years ago

Oh, you finally figured it out.

I actually fixed the bug. Mine had a different root cause called WM_PAINT Storm. This seems to be a WPF specific bug. Some times after waking from sleep or switching user (Win + L), every window receives a WM_PAINT message. Which the WPF's dispatcher gets and do tasks such as rendering the Window content to the actual window. This again sends another WM_PAINT message which results in a loop. This loop makes the UI Thread un-responsive and stops rendering of content, resulting in a frozen or black window.

I'm not sure of yours though 🤷‍♂️. TabControl is not from ModernWpf so, I'm sure this is caused by WPF. Can you provide a repro of your issue so that I can help you?

milos12345 commented 4 years ago

@ShankarBUS Since yesterday I keep trying to reproduce it in an empty project with just ModernWPF but I still fail. Most that I could narrow it is that resuming from windows lock screen will cause this and this line in app.xaml makes a difference is <ui:XamlControlsResources /> If I comment-out this line, the butchered version of my program can open window and renders all fine (but without style), otherwise just white window.

To reproduce it:

In this butchered version if I click once on MainWindow (which is just blank window with a button) the same shortcut will open that windows with TabControl fine and all subsequent times, until I lock screen again

I am not sure if it is related to the above stack trace anymore, but please let me know if it sounds familliar in any way. I'll keep trying to reproduce it in a empty project

milos12345 commented 4 years ago

I have made simple example to reproduce window opening blank after computer unlock if it contains TabControl If you remove ModernWPF's it works again https://github.com/milos12345/WpfEmptyWindowIssue Maybe @Kinnara already knows what might be the reason for this

milos12345 commented 4 years ago

For a test, I've replaced Style for TabControl/TabItem with a first one I've googled https://stackoverflow.com/a/31365307/967565 and the issue is fixed in one window; 2nd one still uses Style from ModernWPF and still results in whole window blank after Lock/Unlock, so the issue is definitely is somewhere in TabControl/TabItem Style of ModernWPF

Kinnara commented 4 years ago

I have made simple example to reproduce window opening blank after computer unlock if it contains TabControl If you remove ModernWPF's it works again https://github.com/milos12345/WpfEmptyWindowIssue Maybe @Kinnara already knows what might be the reason for this

Could you please add all project files to that repo? There are a few missing.

milos12345 commented 4 years ago

Could you please add all project files to that repo? There are a few missing.

I have uploaded missing files. The weird thing is that now I need to lock computer twice for the issue to appear consistently I have made a 40s video of how it happens https://youtu.be/_Dmitqt6oKc

Kinnara commented 3 years ago

Thanks. Unfortunately, I can't seem to reproduce the problem on my computer, even if I lock it multiple times in a row. Does this workaround help?

m1l commented 3 years ago

I already had that handling of the WM_NCHITTEST in my program because of other issues (Logitech mouse-wheel and I thinks there was also something else, but didn't document the reason)