ソースを参照

Added DoubleEdit

Kenric Nugteren 1 年間 前
コミット
155004404b
2 ファイル変更86 行追加0 行削除
  1. 29 0
      inabox.wpf/Editors/DoubleEdit.xaml
  2. 57 0
      inabox.wpf/Editors/DoubleEdit.xaml.cs

+ 29 - 0
inabox.wpf/Editors/DoubleEdit.xaml

@@ -0,0 +1,29 @@
+<wpf:ThemableWindow x:Class="InABox.WPF.DoubleEdit"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             xmlns:sf="http://schemas.syncfusion.com/wpf"
+        xmlns:wpf="clr-namespace:InABox.Wpf"
+        mc:Ignorable="d"
+        Title="DoubleEdit" Height="200" Width="300">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*" />
+            <RowDefinition Height="40" />
+        </Grid.RowDefinitions>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="Auto" />
+            <ColumnDefinition Width="*" />
+            <ColumnDefinition Width="80" />
+            <ColumnDefinition Width="80" />
+        </Grid.ColumnDefinitions>
+        <Label x:Name="Label" Grid.Row="0" Grid.Column="0" Margin="10" HorizontalAlignment="Left"
+               HorizontalContentAlignment="Left" VerticalAlignment="Stretch" VerticalContentAlignment="Center"
+               Content="Enter Value" />
+        <sf:DoubleTextBox x:Name="Editor" Grid.Row="0" Grid.Column="1" Margin="20" Grid.ColumnSpan="3"
+                            HorizontalAlignment="Stretch" VerticalAlignment="Center" Value="0" TextAlignment="Center" />
+        <Button x:Name="OK" Grid.Row="1" Grid.Column="2" Margin="5" Content="OK" Click="OK_Click" />
+        <Button x:Name="Cancel" Grid.Row="1" Grid.Column="3" Margin="5" Content="Cancel" Click="Cancel_Click" />
+    </Grid>
+</wpf:ThemableWindow>

+ 57 - 0
inabox.wpf/Editors/DoubleEdit.xaml.cs

@@ -0,0 +1,57 @@
+using InABox.Wpf;
+using System.Windows;
+
+namespace InABox.WPF
+{
+    /// <summary>
+    ///     Interaction logic for NumberEdit.xaml
+    /// </summary>
+    public partial class DoubleEdit : ThemableWindow
+    {
+        public DoubleEdit(string title, double min, double max, double value)
+        {
+            InitializeComponent();
+            Title = title;
+            Value = value;
+            Editor.MinValue = min;
+            Editor.MaxValue = max;
+        }
+
+        public double 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.MinValue && Editor.Value <= Editor.MaxValue)
+            {
+                DialogResult = true;
+                Close();
+            }
+            else
+            {
+                MessageBox.Show($"Value must be in range [{Editor.MinValue}, {Editor.MaxValue}]");
+            }
+        }
+
+        private void Cancel_Click(object sender, RoutedEventArgs e)
+        {
+            DialogResult = false;
+            Close();
+        }
+
+        public static bool Execute(string title, double min, double max, ref double value)
+        {
+            var edit = new DoubleEdit(title, min, max, value);
+            if (edit.ShowDialog() == true)
+            {
+                value = edit.Value;
+                return true;
+            }
+
+            return false;
+        }
+    }
+}