更新整理
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
public class ChooseBox : TextBox
|
||||
public class ChooseBox : System.Windows.Controls.TextBox
|
||||
{
|
||||
private Button PART_ChooseButton;
|
||||
private System.Windows.Controls.Button PART_ChooseButton;
|
||||
|
||||
static ChooseBox()
|
||||
{ DefaultStyleKeyProperty.OverrideMetadata(typeof(ChooseBox), new FrameworkPropertyMetadata(typeof(ChooseBox))); }
|
||||
@@ -12,24 +12,39 @@ public class ChooseBox : TextBox
|
||||
#region Event Implement Function
|
||||
private void PART_ChooseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
switch(ChooseBoxType)
|
||||
switch (ChooseBoxType)
|
||||
{
|
||||
case ChooseBoxType.SingleFile:
|
||||
OpenFileDialog openFileDialog =
|
||||
new()
|
||||
{
|
||||
Multiselect = false,
|
||||
//"文本文件|*.*|C#文件|*.cs|所有文件|*.*"
|
||||
Filter = Filter
|
||||
};
|
||||
if(openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
Multiselect = false,
|
||||
//"文本文件|*.*|C#文件|*.cs|所有文件|*.*"
|
||||
Filter = Filter
|
||||
};
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
this.Text = openFileDialog.FileName;
|
||||
break;
|
||||
case ChooseBoxType.MultiFile:
|
||||
OpenFileDialog multiFileDialog =
|
||||
new()
|
||||
{
|
||||
Multiselect = true,
|
||||
Filter = Filter
|
||||
};
|
||||
if (multiFileDialog.ShowDialog() == true)
|
||||
{
|
||||
string fileName = string.Empty;
|
||||
foreach (var item in multiFileDialog.FileNames)
|
||||
{
|
||||
fileName += item + ";";
|
||||
}
|
||||
this.Text = fileName.TrimEnd(';');
|
||||
}
|
||||
break;
|
||||
case ChooseBoxType.Folder:
|
||||
var folderDialog = new VistaFolderBrowserDialog();
|
||||
if(folderDialog.ShowDialog() == true)
|
||||
if (folderDialog.ShowDialog() == true)
|
||||
this.Text = folderDialog.SelectedPath;
|
||||
break;
|
||||
case ChooseBoxType.SaveFile:
|
||||
@@ -40,7 +55,7 @@ public class ChooseBox : TextBox
|
||||
DefaultExt = DefaultExt, //设置默认格式(可以不设)
|
||||
AddExtension = true //设置自动在文件名中添加扩展名
|
||||
};
|
||||
if(fileDialog.ShowDialog() == true)
|
||||
if (fileDialog.ShowDialog() == true)
|
||||
this.Text = fileDialog.FileName;
|
||||
break;
|
||||
}
|
||||
@@ -51,9 +66,8 @@ public class ChooseBox : TextBox
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
PART_ChooseButton = this.GetTemplateChild("PART_ChooseButton") as Button;
|
||||
if(PART_ChooseButton != null)
|
||||
PART_ChooseButton = this.GetTemplateChild("PART_ChooseButton") as System.Windows.Controls.Button;
|
||||
if (PART_ChooseButton != null)
|
||||
{
|
||||
PART_ChooseButton.Click += PART_ChooseButton_Click;
|
||||
}
|
||||
@@ -140,5 +154,5 @@ public class ChooseBox : TextBox
|
||||
typeof(string),
|
||||
typeof(ChooseBox),
|
||||
new PropertyMetadata(string.Empty));
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user