using Microsoft.UI.Xaml.Controls; using XFEWarframe.Admin.Models; using XFEWarframe.Desktop.Editing; namespace XFEWarframe.Admin.Views.Dialogs; public sealed partial class GiveItemDialog : ContentDialog { public GiveItemDialog(string name, IReadOnlyList accounts) { InitializeComponent(); Title = "添加 " + name; Suggestions.SetCandidates(AccountInput, accounts); Suggestions.SetSelectedItem(AccountInput, accounts.FirstOrDefault()); } public ItemGrant Result => new((Suggestions.GetSelectedItem(AccountInput) as AccountRow ?? throw new InvalidOperationException("请选择玩家。")).Id, (int)CountInput.Value); private void Validate(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (Suggestions.GetSelectedItem(AccountInput) is null || !double.IsFinite(CountInput.Value) || CountInput.Value != Math.Truncate(CountInput.Value) || CountInput.Value is < 1 or > 100) { args.Cancel = true; ValidationText.Text = "请选择玩家,并输入 1 到 100 之间的整数数量。"; } } }