mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-03-31 10:29:52 +08:00
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using MicaSetup.Helper;
|
|
using MicaSetup.Natives;
|
|
using Microsoft.Xaml.Behaviors;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace MicaSetup.Design.Controls;
|
|
|
|
public sealed class WindowTitleIconBehavior : Behavior<FrameworkElement>
|
|
{
|
|
protected override void OnAttached()
|
|
{
|
|
AssociatedObject.Loaded += Loaded;
|
|
base.OnAttached();
|
|
}
|
|
|
|
protected override void OnDetaching()
|
|
{
|
|
AssociatedObject.Loaded -= Loaded;
|
|
base.OnDetaching();
|
|
}
|
|
|
|
private void Loaded(object sender, EventArgs e)
|
|
{
|
|
AssociatedObject.RegisterAsTitleIcon();
|
|
}
|
|
}
|
|
|
|
public static class RegisterAsTitleIconBehaviorExtension
|
|
{
|
|
public static void RegisterAsTitleIcon(this UIElement self)
|
|
{
|
|
self.MouseLeftButtonDown += (s, e) =>
|
|
{
|
|
if (s is UIElement titleHeader && Window.GetWindow(titleHeader) is Window window)
|
|
{
|
|
if (e.LeftButton == MouseButtonState.Pressed)
|
|
{
|
|
if (User32.GetCursorPos(out POINT pt))
|
|
{
|
|
SystemCommands.ShowSystemMenu(window, new Point(DpiHelper.CalcDPiX(pt.X), DpiHelper.CalcDPiY(pt.Y)));
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|