123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using InABox.Wpf;
- using System.Windows;
- namespace InABox.WPF
- {
- /// <summary>
- /// Interaction logic for NumberEdit.xaml
- /// </summary>
- public partial class NumberEdit : ThemableWindow
- {
- public NumberEdit(string title, int min, int max, int value)
- {
- InitializeComponent();
- Title = title;
- Value = value;
- Editor.Minimum = min;
- Editor.Maximum = max;
- }
- public int Value
- {
- get => Editor.Value.HasValue ? Editor.Value.Value : 0;
- set => Editor.Value = value;
- }
- private void OK_Click(object sender, RoutedEventArgs e)
- {
- if(Editor.Value >= Editor.Minimum && Editor.Value <= Editor.Maximum)
- {
- DialogResult = true;
- Close();
- }
- else
- {
- MessageBox.Show($"Value must be in range [{Editor.Minimum}, {Editor.Maximum}]");
- }
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
- public static bool Execute(string title, int min, int max, ref int value)
- {
- var edit = new NumberEdit(title, min, max, value);
- if (edit.ShowDialog() == true)
- {
- value = edit.Value;
- return true;
- }
- return false;
- }
- }
- }
|