1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace Venus_MainPages.Views
- {
- /// <summary>
- /// InputFileNameDialogView.xaml 的交互逻辑
- /// </summary>
- public partial class InputFileNameDialogView : Window
- {
- public InputFileNameDialogView()
- {
- InitializeComponent();
- }
- public InputFileNameDialogView(string displayName)
- {
- InitializeComponent();
- this.Title = displayName;
- }
- 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);
- }
- }
- 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;
- }
- public string FileName
- {
- get
- {
- return this.textBoxInput.Text;
- }
- set
- {
- this.textBoxInput.Text = value;
- }
- }
- }
- }
|