-
-
Notifications
You must be signed in to change notification settings - Fork 983
fix(controls): fixes #1670 - TitleBar throws NRE when Collapsed #1671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -676,7 +676,8 @@ or PInvoke.WM_NCLBUTTONUP | |
|
|
||
| foreach (TitleBarButton button in _buttons) | ||
| { | ||
| if (!button.ReactToHwndHook(message, lParam, out IntPtr returnIntPtr)) | ||
| // Check if button is null to avoid potential NullReferenceException if OnApplyTemplate hasn't been called yet, e.g. when TitleBar has Visibility == Collapsed. | ||
| if (button == null || !button.ReactToHwndHook(message, lParam, out IntPtr returnIntPtr)) | ||
| { | ||
|
Comment on lines
+679
to
681
|
||
| continue; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_buttonsis declared asTitleBarButton[]but is initialized with null elements untilOnApplyTemplate()runs. Addingbutton == nullhere fixes the immediate NRE, but it leaves nullability inconsistent and still assumes_buttonscontains no nulls in the inner loop (e.g.,anotherButton.IsHovered). Consider making_buttonsaTitleBarButton?[](or using an_isTemplateAppliedflag /Array.Empty<TitleBarButton>()until templated) and iterating only over non-null buttons to keep the hook logic robust and aligned with nullable reference types.