RecipeNameInputDlg.xaml.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. namespace Venus_Themes.UserControls
  6. {
  7. /// <summary>
  8. /// RecipeNameInputDlg.xaml 的交互逻辑
  9. /// </summary>
  10. public partial class RecipeNameInputDlg : Window
  11. {
  12. public RecipeNameInputDlg(string caption, bool hasHV)
  13. {
  14. InitializeComponent();
  15. labelCaption.Text = caption;
  16. this.buttonOK.IsEnabled = false;
  17. this.textBoxInput.Focus();
  18. if (!hasHV)
  19. {
  20. chuckRadioButton.Visibility = Visibility.Collapsed;
  21. dechuckRadioButton.Visibility = Visibility.Collapsed;
  22. }
  23. }
  24. public RecipeNameInputDlg(string caption, string title)
  25. {
  26. InitializeComponent();
  27. Title = title;
  28. labelCaption.Text = caption;
  29. this.buttonOK.IsEnabled = false;
  30. this.textBoxInput.Focus();
  31. }
  32. private void buttonCancel_Click(object sender, RoutedEventArgs e)
  33. {
  34. this.DialogResult = false;
  35. }
  36. private void buttonOK_Click(object sender, RoutedEventArgs e)
  37. {
  38. this.DialogResult = true;
  39. }
  40. private void textBoxInput_TextChanged(object sender, TextChangedEventArgs e)
  41. {
  42. if (textBoxInput.Text == "")
  43. {
  44. this.buttonOK.IsEnabled = false;
  45. }
  46. else
  47. {
  48. this.buttonOK.IsEnabled = IsValidFileName(textBoxInput.Text);
  49. }
  50. }
  51. /// <summary>
  52. /// 输入文字
  53. /// </summary>
  54. public string InputText
  55. {
  56. get
  57. {
  58. return this.textBoxInput.Text;
  59. }
  60. set
  61. {
  62. this.textBoxInput.Text = value;
  63. }
  64. }
  65. public string SelectedType { get; set; }
  66. /// <summary>
  67. /// 文件名校验
  68. /// </summary>
  69. /// <param name="strIn"></param>
  70. /// <returns></returns>
  71. bool IsValidFileName(string strIn)
  72. {
  73. string[] paths = strIn.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
  74. Regex regEx = new Regex(@"^[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*$");
  75. foreach (var path in paths)
  76. {
  77. if (!regEx.IsMatch(path))
  78. return false;
  79. }
  80. return true;
  81. }
  82. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  83. {
  84. SelectedType = (sender as RadioButton).Content.ToString();
  85. }
  86. }
  87. }