فهرست منبع

DoubleEdit now confirms on enter

Kenric Nugteren 1 سال پیش
والد
کامیت
87303ba21d
2فایلهای تغییر یافته به همراه25 افزوده شده و 4 حذف شده
  1. 5 2
      inabox.wpf/Editors/DoubleEdit.xaml
  2. 20 2
      inabox.wpf/Editors/DoubleEdit.xaml.cs

+ 5 - 2
inabox.wpf/Editors/DoubleEdit.xaml

@@ -6,7 +6,9 @@
              xmlns:sf="http://schemas.syncfusion.com/wpf"
         xmlns:wpf="clr-namespace:InABox.Wpf"
         mc:Ignorable="d"
-        Title="DoubleEdit" Height="200" Width="300">
+        Title="DoubleEdit" Height="200" Width="300"
+                    Loaded="ThemableWindow_Loaded"
+                    KeyUp="Editor_KeyUp">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="*" />
@@ -22,7 +24,8 @@
                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" />
+                            HorizontalAlignment="Stretch" VerticalAlignment="Center" Value="0" TextAlignment="Center"
+                          KeyUp="Editor_KeyUp"/>
         <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>

+ 20 - 2
inabox.wpf/Editors/DoubleEdit.xaml.cs

@@ -23,9 +23,9 @@ namespace InABox.WPF
             set => Editor.Value = value;
         }
 
-        private void OK_Click(object sender, RoutedEventArgs e)
+        private void Confirm()
         {
-            if(Editor.Value >= Editor.MinValue && Editor.Value <= Editor.MaxValue)
+            if (Editor.Value >= Editor.MinValue && Editor.Value <= Editor.MaxValue)
             {
                 DialogResult = true;
                 Close();
@@ -36,6 +36,11 @@ namespace InABox.WPF
             }
         }
 
+        private void OK_Click(object sender, RoutedEventArgs e)
+        {
+            Confirm();
+        }
+
         private void Cancel_Click(object sender, RoutedEventArgs e)
         {
             DialogResult = false;
@@ -53,5 +58,18 @@ namespace InABox.WPF
 
             return false;
         }
+
+        private void ThemableWindow_Loaded(object sender, RoutedEventArgs e)
+        {
+            Editor.Focus();
+        }
+
+        private void Editor_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
+        {
+            if(e.Key == System.Windows.Input.Key.Enter)
+            {
+                Confirm();
+            }
+        }
     }
 }