using HandyControl.Controls; using SparkClient.Model.Helper; using SparkClient.ViewModel; using SparkClient.ViewModel.Dialog; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace SparkClient.Views.Dialog { /// /// StartDialog.xaml 的交互逻辑 /// public partial class StartDialog { public BaseViewModel ViewModel = null; public StartDialog() { WindowStartupLocation = WindowStartupLocation.CenterScreen; InitializeComponent(); // 动态设置圆角裁剪 this.Loaded += (s, e) => ApplyCornerRadiusClip(); this.SizeChanged += (s, e) => ApplyCornerRadiusClip(); // 保证在大小改变时也裁剪 this.Width = 562; this.Height = 222; this.ViewModel = new StartDialogVM(); this.DataContext = this.ViewModel; } #region 重写窗体操作按钮 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 Minimize_Click(object sender, MouseButtonEventArgs e) { this.WindowState = WindowState.Minimized; } private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { try { this.DragMove(); } catch (InvalidOperationException ex) { } } } #endregion private void Close_Click(object sender, RoutedEventArgs e) { this.Close(); } private void Ok_Click(object sender, RoutedEventArgs e) { if(Id.Text.Trim().Length>0) { this.Close(); } } private void ApplyCornerRadiusClip() { // 使用矩形几何生成圆角裁剪 this.Border.Clip = new RectangleGeometry { Rect = new Rect(0, 0, this.Border.ActualWidth, this.Border.ActualHeight), RadiusX = this.Border.CornerRadius.TopLeft, // 使用 Border 的 CornerRadius RadiusY = this.Border.CornerRadius.TopLeft }; } } }