using System;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
namespace Venus_Themes.UserControls
{
///
/// RecipeNameInputDlg.xaml 的交互逻辑
///
public partial class RecipeNameInputDlg : Window
{
public RecipeNameInputDlg(string caption, bool hasHV)
{
InitializeComponent();
labelCaption.Text = caption;
this.buttonOK.IsEnabled = false;
this.textBoxInput.Focus();
if (!hasHV)
{
chuckRadioButton.Visibility = Visibility.Collapsed;
dechuckRadioButton.Visibility = Visibility.Collapsed;
}
}
public RecipeNameInputDlg(string caption, string title)
{
InitializeComponent();
Title = title;
labelCaption.Text = caption;
this.buttonOK.IsEnabled = false;
this.textBoxInput.Focus();
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
private void buttonOK_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void textBoxInput_TextChanged(object sender, TextChangedEventArgs e)
{
if (textBoxInput.Text == "")
{
this.buttonOK.IsEnabled = false;
}
else
{
this.buttonOK.IsEnabled = IsValidFileName(textBoxInput.Text);
}
}
///
/// 输入文字
///
public string InputText
{
get
{
return this.textBoxInput.Text;
}
set
{
this.textBoxInput.Text = value;
}
}
public string SelectedType { get; set; }
///
/// 文件名校验
///
///
///
bool IsValidFileName(string strIn)
{
string[] paths = strIn.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
Regex regEx = new Regex(@"^[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*$");
foreach (var path in paths)
{
if (!regEx.IsMatch(path))
return false;
}
return true;
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
SelectedType = (sender as RadioButton).Content.ToString();
}
}
}