2025-05-05 17:04:06 +08:00
|
|
|
|
using WPFluent.Controls;
|
2025-02-10 20:53:40 +08:00
|
|
|
|
using WPFluent.Interop;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WPFluent.Appearance;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-24 20:56:44 +08:00
|
|
|
|
/// 便于管理窗口背景。
|
2025-02-10 20:53:40 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <example>
|
|
|
|
|
|
/// <code lang="csharp"> /// WindowBackgroundManager.UpdateBackground( /// observedWindow.RootVisual, ///
|
|
|
|
|
|
/// currentApplicationTheme, /// observedWindow.Backdrop /// ); ///</code>
|
|
|
|
|
|
/// </example>
|
|
|
|
|
|
public static class WindowBackgroundManager
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Forces change to application background. Required if custom background effect was previously applied.
|
|
|
|
|
|
/// </summary>
|
2025-05-05 17:04:06 +08:00
|
|
|
|
public static void UpdateBackground(Window? window, ThemeType applicationTheme, WindowBackdropType backdrop)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
2025-04-24 20:56:44 +08:00
|
|
|
|
if (window is null)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//_ = WindowBackdrop.RemoveBackdrop(window);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
|
2025-05-05 17:04:06 +08:00
|
|
|
|
if (applicationTheme == ThemeType.Unknow)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
backdrop = WindowBackdropType.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-05 17:04:06 +08:00
|
|
|
|
if (backdrop is not WindowBackdropType.None)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
_ = WindowBackdrop.RemoveBackground(window);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//_ = WindowBackdrop.ApplyBackdrop(window, backdrop);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
|
2025-05-05 17:04:06 +08:00
|
|
|
|
if (applicationTheme is ThemeType.Dark)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//ApplyDarkThemeToWindow(window);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//RemoveDarkThemeFromWindow(window);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//_ = WindowBackdrop.RemoveTitlebarBackground(window);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
foreach (object? subWindow in window.OwnedWindows)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
2025-04-24 20:56:44 +08:00
|
|
|
|
if (subWindow is Window windowSubWindow)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//_ = WindowBackdrop.ApplyBackdrop(windowSubWindow, backdrop);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
|
2025-05-05 17:04:06 +08:00
|
|
|
|
if (applicationTheme is ThemeType.Dark)
|
2025-02-10 20:53:40 +08:00
|
|
|
|
{
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//ApplyDarkThemeToWindow(windowSubWindow);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//RemoveDarkThemeFromWindow(windowSubWindow);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
//_ = WindowBackdrop.RemoveTitlebarBackground(window);
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|