Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private void OnTemplateButtonClick(TitleBarButtonType buttonType)
}

/// <summary>
/// Listening window hooks after rendering window content to SizeToContent support
/// Listening window hooks after rendering window content to SizeToContent support
/// </summary>
private void OnWindowContentRendered(object? sender, EventArgs e)
{
Expand All @@ -607,8 +607,17 @@ private void OnWindowContentRendered(object? sender, EventArgs e)
window.ContentRendered -= OnWindowContentRendered;

IntPtr handle = new WindowInteropHelper(window).Handle;
HwndSource windowSource =
HwndSource.FromHwnd(handle) ?? throw new InvalidOperationException("Window source is null");
if (handle == IntPtr.Zero)
{
return;
}

HwndSource? windowSource = HwndSource.FromHwnd(handle);
if (windowSource == null)
{
return;
}

windowSource.AddHook(HwndSourceHook);
}

Expand Down
Loading