RecipeNameInputDlg.xaml.cs 2.7 KB

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