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.
106 lines
3.3 KiB
106 lines
3.3 KiB
using HandyControl.Controls; |
|
using SparkClient.ViewModel; |
|
using SparkClient.ViewModel.Dialog; |
|
using System.IO; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
using System.Windows.Input; |
|
using System.Windows.Media; |
|
|
|
namespace SparkClient.Views.Dialog |
|
{ |
|
/// <summary> |
|
/// JsonImport.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class JsonImport |
|
{ |
|
public BaseViewModel ViewModel = null; |
|
public JsonImport() |
|
{ |
|
InitializeComponent(); |
|
WindowStartupLocation = WindowStartupLocation.CenterScreen; |
|
// 动态设置圆角裁剪 |
|
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_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 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) |
|
{ |
|
DialogResult = false; |
|
this.Close(); |
|
} |
|
private void open_Click(object sender, RoutedEventArgs e) |
|
{ |
|
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); |
|
openFileDialog.Filter = "Text files (*.json)|*.json|All files (*.*)|*.*"; |
|
if (openFileDialog.ShowDialog() == true) |
|
{ |
|
string filename = openFileDialog.FileName; |
|
if (File.Exists(filename)) |
|
{ |
|
FilePath.Text = filename; |
|
} |
|
} |
|
} |
|
private void Ok_Click(object sender, RoutedEventArgs e) |
|
{ |
|
if (FilePath.Text.Trim().Length > 0) { |
|
DialogResult = true; |
|
this.Close(); |
|
} |
|
else |
|
{ |
|
Growl.Error("请选择导入json文件"); |
|
} |
|
} |
|
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 |
|
}; |
|
} |
|
} |
|
}
|
|
|