Describe the bug
When TitleBar is set to a Collapsed visilibity, the Window it resides in throws NRE continuously when hovering with mouse:
System.NullReferenceException: Object reference not set to an instance of an object.
at Wpf.Ui.Controls.TitleBar.HwndSourceHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in C:\dev\wpfui-mimmo\src\Wpf.Ui\Controls\TitleBar\TitleBar.cs:line 679
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)
In this execution path we are trying to handle the hovering on buttons: if buttons are not yet built, we can safely skip this check.
I checked this issue too #962 but seems not related to this situation.
To Reproduce
- Open WPF-UI solution, Wpf.Ui.Gallery project.
- Edit
Wpf.Ui.Gallery.Views.Windows.MainWindow by adding Visibility="Collapsed" to TitleBar, as in following screenshot:
- Set breakpoint at TitleBar line ~678
- Run Gallery program and move mouse inside window (bug does not happen when mouse is not hovering Window)
- Breakpoint hits with NULL values inside the
_buttons array:
The problem is that _buttons array is filled with buttons in OnApplyTemplate() method, that is not called if TitleBar is collapsed.
Expected behavior
The expected behavior is to simply fallback to no-op on buttons hovering check.
Screenshots
No response
OS version
Win11
.NET version
.NET 10
WPF-UI NuGet version
4.2.0
Additional context
No response
Describe the bug
When TitleBar is set to a Collapsed visilibity, the Window it resides in throws NRE continuously when hovering with mouse:
In this execution path we are trying to handle the hovering on buttons: if buttons are not yet built, we can safely skip this check.
I checked this issue too #962 but seems not related to this situation.
To Reproduce
Wpf.Ui.Gallery.Views.Windows.MainWindowby addingVisibility="Collapsed"to TitleBar, as in following screenshot:_buttonsarray:The problem is that _buttons array is filled with buttons in
OnApplyTemplate()method, that is not called if TitleBar is collapsed.Expected behavior
The expected behavior is to simply fallback to no-op on buttons hovering check.
Screenshots
No response
OS version
Win11
.NET version
.NET 10
WPF-UI NuGet version
4.2.0
Additional context
No response