整理控件库
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Win32;
|
||||
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
@@ -9,12 +10,24 @@ public class ChooseBox : System.Windows.Controls.TextBox
|
||||
static ChooseBox()
|
||||
{ DefaultStyleKeyProperty.OverrideMetadata(typeof(ChooseBox), new FrameworkPropertyMetadata(typeof(ChooseBox))); }
|
||||
|
||||
|
||||
public string PlaceholderText
|
||||
{
|
||||
get { return (string)GetValue(PlaceholderTextProperty); }
|
||||
set { SetValue(PlaceholderTextProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PlaceholderTextProperty =
|
||||
DependencyProperty.Register("PlaceholderText", typeof(string), typeof(ChooseBox), new PropertyMetadata(string.Empty));
|
||||
|
||||
|
||||
|
||||
#region Event Implement Function
|
||||
private void PART_ChooseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
switch (ChooseBoxType)
|
||||
switch (ChooseType)
|
||||
{
|
||||
case ChooseBoxType.SingleFile:
|
||||
case ChooseType.SingleFile:
|
||||
OpenFileDialog openFileDialog =
|
||||
new()
|
||||
{
|
||||
@@ -25,7 +38,7 @@ public class ChooseBox : System.Windows.Controls.TextBox
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
this.Text = openFileDialog.FileName;
|
||||
break;
|
||||
case ChooseBoxType.MultiFile:
|
||||
case ChooseType.MultiFiles:
|
||||
OpenFileDialog multiFileDialog =
|
||||
new()
|
||||
{
|
||||
@@ -37,17 +50,17 @@ public class ChooseBox : System.Windows.Controls.TextBox
|
||||
string fileName = string.Empty;
|
||||
foreach (var item in multiFileDialog.FileNames)
|
||||
{
|
||||
fileName += item + ";";
|
||||
fileName += $"{item};";
|
||||
}
|
||||
this.Text = fileName.TrimEnd(';');
|
||||
}
|
||||
break;
|
||||
case ChooseBoxType.Folder:
|
||||
case ChooseType.Folder:
|
||||
var folderDialog = new VistaFolderBrowserDialog();
|
||||
if (folderDialog.ShowDialog() == true)
|
||||
this.Text = folderDialog.SelectedPath;
|
||||
break;
|
||||
case ChooseBoxType.SaveFile:
|
||||
case ChooseType.SaveFile:
|
||||
var fileDialog = new SaveFileDialog
|
||||
{
|
||||
Filter = Filter, //设置文件类型
|
||||
@@ -91,17 +104,39 @@ public class ChooseBox : System.Windows.Controls.TextBox
|
||||
#endregion
|
||||
|
||||
#region ChooseBoxType
|
||||
public ChooseBoxType ChooseBoxType
|
||||
public ChooseType ChooseType
|
||||
{
|
||||
get { return (ChooseBoxType)GetValue(ChooseBoxTypeProperty); }
|
||||
set { SetValue(ChooseBoxTypeProperty, value); }
|
||||
get { return (ChooseType)GetValue(ChooseTypeProperty); }
|
||||
set { SetValue(ChooseTypeProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ChooseBoxTypeProperty = DependencyProperty.Register(
|
||||
nameof(ChooseBoxType),
|
||||
typeof(ChooseBoxType),
|
||||
public static readonly DependencyProperty ChooseTypeProperty = DependencyProperty.Register(
|
||||
nameof(ChooseType),
|
||||
typeof(ChooseType),
|
||||
typeof(ChooseBox),
|
||||
new PropertyMetadata(ChooseBoxType.SingleFile));
|
||||
new PropertyMetadata(ChooseType.SingleFile, OnChooseTypeChanged));
|
||||
|
||||
private static void OnChooseTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is ChooseBox chooseBox)
|
||||
{
|
||||
switch ((ChooseType)e.NewValue)
|
||||
{
|
||||
case ChooseType.SingleFile:
|
||||
chooseBox.PlaceholderText = "请选择文件";
|
||||
break;
|
||||
case ChooseType.MultiFiles:
|
||||
chooseBox.PlaceholderText = "请选择多个文件";
|
||||
break;
|
||||
case ChooseType.Folder:
|
||||
chooseBox.PlaceholderText = "请选择文件夹";
|
||||
break;
|
||||
case ChooseType.SaveFile:
|
||||
chooseBox.PlaceholderText = "请选择保存文件路径";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ChooseButtonWidth
|
||||
|
||||
Reference in New Issue
Block a user