| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System.Windows;
- using HandyControl.Controls;
- namespace TeamAAS.Dialogs.Dialogs
- {
- /// <summary>
- /// 输入对话框,用于获取用户文本输入。
- /// 通过 DialogHelper.Input 调用。
- /// </summary>
- public partial class InputDialog
- {
- /// <summary>用户输入的文本,点击确定后有效</summary>
- public string InputText { get; private set; }
- /// <summary>用户是否点击了确定</summary>
- public bool Result { get; private set; }
- public InputDialog()
- {
- InitializeComponent();
- UiScaler.Attach(this); // 分辨率/DPI 自适应
- Loaded += (s, e) => { InputBox.Focus(); InputBox.SelectAll(); };
- }
- /// <summary>
- /// 配置输入对话框。
- /// </summary>
- /// <param name="label">提示文本</param>
- /// <param name="title">窗口标题</param>
- /// <param name="defaultText">默认填入的文本</param>
- /// <param name="placeholder">占位提示文本</param>
- public void Setup(string label, string title = "输入", string defaultText = "", string placeholder = "请输入...")
- {
- Title = title;
- LabelText.Text = label;
- InputBox.Text = defaultText;
- }
- private void BtnOK_Click(object sender, RoutedEventArgs e)
- {
- InputText = InputBox.Text;
- Result = true;
- Close();
- }
- private void BtnCancel_Click(object sender, RoutedEventArgs e)
- {
- InputText = null;
- Result = false;
- Close();
- }
- }
- }
|