InputFileNameDialogView.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.Shapes;
  15. namespace Venus_MainPages.Views
  16. {
  17. /// <summary>
  18. /// InputFileNameDialogView.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class InputFileNameDialogView : Window
  21. {
  22. public InputFileNameDialogView()
  23. {
  24. InitializeComponent();
  25. }
  26. public InputFileNameDialogView(string displayName)
  27. {
  28. InitializeComponent();
  29. this.Title = displayName;
  30. }
  31. private void buttonCancel_Click(object sender, RoutedEventArgs e)
  32. {
  33. this.DialogResult = false;
  34. }
  35. private void buttonOK_Click(object sender, RoutedEventArgs e)
  36. {
  37. this.DialogResult = true;
  38. }
  39. private void textBoxInput_TextChanged(object sender, TextChangedEventArgs e)
  40. {
  41. if (textBoxInput.Text == "")
  42. {
  43. this.buttonOK.IsEnabled = false;
  44. }
  45. else
  46. {
  47. this.buttonOK.IsEnabled = IsValidFileName(textBoxInput.Text);
  48. }
  49. }
  50. bool IsValidFileName(string strIn)
  51. {
  52. string[] paths = strIn.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
  53. Regex regEx = new Regex(@"^[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*$");
  54. foreach (var path in paths)
  55. {
  56. if (!regEx.IsMatch(path))
  57. return false;
  58. }
  59. return true;
  60. }
  61. public string FileName
  62. {
  63. get
  64. {
  65. return this.textBoxInput.Text;
  66. }
  67. set
  68. {
  69. this.textBoxInput.Text = value;
  70. }
  71. }
  72. }
  73. }