InputDialog.xaml.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Windows;
  2. using HandyControl.Controls;
  3. namespace TeamAAS.Dialogs.Dialogs
  4. {
  5. /// <summary>
  6. /// 输入对话框,用于获取用户文本输入。
  7. /// 通过 DialogHelper.Input 调用。
  8. /// </summary>
  9. public partial class InputDialog
  10. {
  11. /// <summary>用户输入的文本,点击确定后有效</summary>
  12. public string InputText { get; private set; }
  13. /// <summary>用户是否点击了确定</summary>
  14. public bool Result { get; private set; }
  15. public InputDialog()
  16. {
  17. InitializeComponent();
  18. UiScaler.Attach(this); // 分辨率/DPI 自适应
  19. Loaded += (s, e) => { InputBox.Focus(); InputBox.SelectAll(); };
  20. }
  21. /// <summary>
  22. /// 配置输入对话框。
  23. /// </summary>
  24. /// <param name="label">提示文本</param>
  25. /// <param name="title">窗口标题</param>
  26. /// <param name="defaultText">默认填入的文本</param>
  27. /// <param name="placeholder">占位提示文本</param>
  28. public void Setup(string label, string title = "输入", string defaultText = "", string placeholder = "请输入...")
  29. {
  30. Title = title;
  31. LabelText.Text = label;
  32. InputBox.Text = defaultText;
  33. }
  34. private void BtnOK_Click(object sender, RoutedEventArgs e)
  35. {
  36. InputText = InputBox.Text;
  37. Result = true;
  38. Close();
  39. }
  40. private void BtnCancel_Click(object sender, RoutedEventArgs e)
  41. {
  42. InputText = null;
  43. Result = false;
  44. Close();
  45. }
  46. }
  47. }