Skip to content

Commit

Permalink
Merge branch 'development' into feature/4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski committed Jun 10, 2024
2 parents 736bc9b + cc35ab2 commit b564bf4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Wpf.Ui/Appearance/WindowBackgroundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ WindowBackdropType backdrop
}

_ = WindowBackdrop.ApplyBackdrop(window, backdrop);

if (applicationTheme is ApplicationTheme.Dark)
{
ApplyDarkThemeToWindow(window);
Expand All @@ -109,6 +110,8 @@ WindowBackdropType backdrop
RemoveDarkThemeFromWindow(window);
}

_ = WindowBackdrop.RemoveTitlebarBackground(window);

foreach (object? subWindow in window.OwnedWindows)
{
if (subWindow is Window windowSubWindow)
Expand All @@ -123,6 +126,8 @@ WindowBackdropType backdrop
{
RemoveDarkThemeFromWindow(windowSubWindow);
}

_ = WindowBackdrop.RemoveTitlebarBackground(window);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Wpf.Ui/Controls/FluentWindow/FluentWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ protected virtual void OnBackdropTypeChanged(WindowBackdropType oldValue, Window
if (WindowBackdrop.IsSupported(newValue) && WindowBackdrop.RemoveBackground(this))
{
_ = WindowBackdrop.ApplyBackdrop(this, newValue);

_ = WindowBackdrop.RemoveTitlebarBackground(this);
}
}

Expand Down
38 changes: 36 additions & 2 deletions src/Wpf.Ui/Controls/Window/WindowBackdrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static bool IsSupported(WindowBackdropType backdropType)
/// <param name="window">The window to which the backdrop effect will be applied.</param>
/// <param name="backdropType">The type of backdrop effect to apply. Determines the visual appearance of the window's backdrop.</param>
/// <returns><see langword="true"/> if the operation was successful; otherwise, <see langword="false"/>.</returns>
public static bool ApplyBackdrop(System.Windows.Window window, WindowBackdropType backdropType)
public static bool ApplyBackdrop(System.Windows.Window? window, WindowBackdropType backdropType)
{
if (window is null)
{
Expand Down Expand Up @@ -216,6 +216,40 @@ public static bool RemoveBackground(System.Windows.Window? window)
return true;
}

public static bool RemoveTitlebarBackground(System.Windows.Window? window)
{
if (window is null)
{
return false;
}

IntPtr windowHandle = new WindowInteropHelper(window).Handle;

if (windowHandle == IntPtr.Zero)
{
return false;
}

HwndSource? windowSource = HwndSource.FromHwnd(windowHandle);

// Remove background from client area
if (windowSource?.Handle != IntPtr.Zero && windowSource?.CompositionTarget != null)
{
// NOTE: https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
// Specifying DWMWA_COLOR_DEFAULT (value 0xFFFFFFFF) for the color will reset the window back to using the system's default behavior for the caption color.
uint titlebarPvAttribute = 0xFFFFFFFE;

Dwmapi.DwmSetWindowAttribute(
windowSource.Handle,
Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR,
ref titlebarPvAttribute,
Marshal.SizeOf(typeof(uint))
);
}

return true;
}

private static bool ApplyDwmwWindowAttrubute(IntPtr hWnd, Dwmapi.DWMSBT dwmSbt)
{
if (hWnd == IntPtr.Zero)
Expand All @@ -228,7 +262,7 @@ private static bool ApplyDwmwWindowAttrubute(IntPtr hWnd, Dwmapi.DWMSBT dwmSbt)
return false;
}

var backdropPvAttribute = (int)dwmSbt;
int backdropPvAttribute = (int)dwmSbt;

var dwmApiResult = Dwmapi.DwmSetWindowAttribute(
hWnd,
Expand Down
16 changes: 16 additions & 0 deletions src/Wpf.Ui/Interop/Dwmapi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,22 @@ public static extern int DwmSetWindowAttribute(
[In] int cbAttribute
);

/// <summary>
/// Sets the value of Desktop Window Manager (DWM) non-client rendering attributes for a window.
/// </summary>
/// <param name="hWnd">The handle to the window for which the attribute value is to be set.</param>
/// <param name="dwAttribute">A flag describing which value to set, specified as a value of the DWMWINDOWATTRIBUTE enumeration.</param>
/// <param name="pvAttribute">A pointer to an object containing the attribute value to set.</param>
/// <param name="cbAttribute">The size, in bytes, of the attribute value being set via the <c>pvAttribute</c> parameter.</param>
/// <returns>If the function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</returns>
[DllImport(Libraries.Dwmapi)]
public static extern int DwmSetWindowAttribute(
[In] IntPtr hWnd,
[In] DWMWINDOWATTRIBUTE dwAttribute,
[In] ref uint pvAttribute,
[In] int cbAttribute
);

/// <summary>
/// Retrieves the current value of a specified Desktop Window Manager (DWM) attribute applied to a window. For programming guidance, and code examples, see Controlling non-client region rendering.
/// </summary>
Expand Down

0 comments on commit b564bf4

Please sign in to comment.