using System.Collections; using System.Windows; using HandyControl.Controls; namespace TeamAAS.Dialogs.Dialogs { /// /// 选择对话框,用于让用户从列表中选择一项。 /// 通过 DialogHelper.Select 调用。 /// public partial class SelectDialog { /// 用户选中的项,点击确定后有效;未选择为 null public object SelectedItem { get; private set; } /// 用户是否点击了确定 public bool Result { get; private set; } public SelectDialog() { InitializeComponent(); UiScaler.Attach(this); // 分辨率/DPI 自适应 } /// /// 配置选择对话框。 /// /// 提示文本 /// 可选项列表 /// 窗口标题 /// 默认选中项 public void Setup(string label, IEnumerable items, string title = "选择", object defaultItem = null) { Title = title; LabelText.Text = label; SelectBox.Items.Clear(); foreach (var item in items) { SelectBox.Items.Add(item); } if (defaultItem != null) { SelectBox.SelectedItem = defaultItem; } else if (SelectBox.Items.Count > 0) { SelectBox.SelectedIndex = 0; } } private void BtnOK_Click(object sender, RoutedEventArgs e) { SelectedItem = SelectBox.SelectedItem; Result = true; Close(); } private void BtnCancel_Click(object sender, RoutedEventArgs e) { SelectedItem = null; Result = false; Close(); } } }