优化更新代码,添加界面功能并整合
This commit is contained in:
79
WPFluent/Appearance/ObservedWindow.cs
Normal file
79
WPFluent/Appearance/ObservedWindow.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
namespace WPFluent.Appearance;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a window that is being observed for changes in appearance.
|
||||
/// </summary>
|
||||
internal class ObservedWindow
|
||||
{
|
||||
private readonly HwndSource _source;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ObservedWindow"/> class.
|
||||
/// </summary>
|
||||
/// <param name="handle">The handle of the window.</param>
|
||||
/// <param name="backdrop">The backdrop type of the window.</param>
|
||||
/// <param name="updateAccents">Indicates whether to update accents.</param>
|
||||
public ObservedWindow(IntPtr handle, WindowBackdropType backdrop, bool updateAccents)
|
||||
{
|
||||
Handle = handle;
|
||||
Backdrop = backdrop;
|
||||
UpdateAccents = updateAccents;
|
||||
HasHook = false;
|
||||
|
||||
HwndSource? windowSource = HwndSource.FromHwnd(handle);
|
||||
_source =
|
||||
windowSource ?? throw new InvalidOperationException("Unable to determine the window source.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a hook to the window.
|
||||
/// </summary>
|
||||
/// <param name="hook">The hook to add.</param>
|
||||
public void AddHook(HwndSourceHook hook)
|
||||
{
|
||||
_source.AddHook(hook);
|
||||
|
||||
HasHook = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a hook from the window.
|
||||
/// </summary>
|
||||
/// <param name="hook">The hook to remove.</param>
|
||||
public void RemoveHook(HwndSourceHook hook)
|
||||
{
|
||||
_source.RemoveHook(hook);
|
||||
|
||||
HasHook = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the backdrop type of the window.
|
||||
/// </summary>
|
||||
public WindowBackdropType Backdrop { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the handle of the window.
|
||||
/// </summary>
|
||||
public IntPtr Handle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the window has a hook.
|
||||
/// </summary>
|
||||
public bool HasHook { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root visual of the window.
|
||||
/// </summary>
|
||||
public Window? RootVisual => (Window?)_source.RootVisual;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether to update accents.
|
||||
/// </summary>
|
||||
public bool UpdateAccents { get; }
|
||||
}
|
||||
Reference in New Issue
Block a user