You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
using System.Windows; |
|
using System.Windows.Controls; |
|
using System.Windows.Input; |
|
using System.Windows.Media; |
|
using SparkClient.ViewModel.BaseWindow; |
|
|
|
namespace SparkClient.Views.BaseWindow; |
|
|
|
public partial class BaseControl |
|
{ |
|
public BaseControl() |
|
{ |
|
InitializeComponent(); |
|
|
|
// 动态设置圆角裁剪 |
|
this.Loaded += (s, e) => ApplyCornerRadiusClip(); |
|
this.SizeChanged += (s, e) => ApplyCornerRadiusClip(); // 保证在大小改变时也裁剪 |
|
} |
|
|
|
private void Border_Minimize_MouseEnter(object sender, MouseEventArgs e) |
|
{ |
|
// 鼠标进入时更改背景色 |
|
if (sender is Border border) |
|
{ |
|
border.Background = new SolidColorBrush(Color.FromArgb(50, 255, 255, 255)); |
|
} |
|
} |
|
private void Border_Close_MouseEnter(object sender, MouseEventArgs e) |
|
{ |
|
// 鼠标进入时更改背景色 |
|
if (sender is Border border) |
|
{ |
|
border.Background = new SolidColorBrush(Color.FromArgb(50, 255, 0, 0)); |
|
} |
|
} |
|
private void Border_MouseLeave(object sender, MouseEventArgs e) |
|
{ |
|
// 鼠标离开时恢复背景色 |
|
if (sender is Border border) |
|
{ |
|
border.Background = new SolidColorBrush(Colors.Transparent); |
|
} |
|
} |
|
|
|
private void ApplyCornerRadiusClip() |
|
{ |
|
// 使用矩形几何生成圆角裁剪 |
|
this.Clip = new RectangleGeometry |
|
{ |
|
Rect = new Rect(0, 0, this.ActualWidth, this.ActualHeight), |
|
RadiusX = this.CornerRadius.TopLeft, // 使用 Border 的 CornerRadius |
|
RadiusY = this.CornerRadius.TopLeft |
|
}; |
|
} |
|
} |