Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Perpetuum.AdminTool/Views/NewItemDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="clr-namespace:Perpetuum.AdminTool.Common"
Title="New Item" Width="960" Height="720"
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
PreviewKeyDown="OnPreviewKeyDown">
<DockPanel>

<!-- Clone picker header -->
Expand All @@ -30,9 +31,9 @@
<TextBlock Grid.Column="0" Text="{Binding StatusMessage}" Foreground="DarkRed"
VerticalAlignment="Center" TextWrapping="Wrap"/>
<Button Grid.Column="1" Content="Save" Width="80" Margin="4,0"
Command="{Binding SaveCommand}"/>
IsDefault="True" Command="{Binding SaveCommand}"/>
<Button Grid.Column="2" Content="Cancel" Width="80"
Command="{Binding CancelCommand}"/>
IsCancel="True" Command="{Binding CancelCommand}"/>
</Grid>
</Border>

Expand Down
14 changes: 14 additions & 0 deletions src/Perpetuum.AdminTool/Views/NewItemDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Perpetuum.AdminTool.NewItem;
using Perpetuum.AdminTool.ViewModels;

Expand All @@ -19,6 +21,18 @@ public NewItemDialog(NewItemDialogViewModel vm)
};
}

// Enter activates the default Save button without moving focus, so a TextBox bound with the
// default LostFocus trigger would still be holding an uncommitted value when Save runs. Push
// it to the source first. Multi-line boxes consume Enter themselves and are left alone.
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key != Key.Enter)
return;

if (Keyboard.FocusedElement is TextBox { AcceptsReturn: false } box)
box.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}

// Tab 1 — Basic
private void PickCategoryMain_Click(object sender, RoutedEventArgs e)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Perpetuum.AdminTool/Views/NewRobotDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="clr-namespace:Perpetuum.AdminTool.Common"
Title="New Robot" Width="1040" Height="760"
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
PreviewKeyDown="OnPreviewKeyDown">
<DockPanel>

<!-- Clone picker header -->
Expand All @@ -30,9 +31,9 @@
<TextBlock Grid.Column="0" Text="{Binding StatusMessage}" Foreground="DarkRed"
VerticalAlignment="Center" TextWrapping="Wrap"/>
<Button Grid.Column="1" Content="Save" Width="80" Margin="4,0"
Command="{Binding SaveCommand}"/>
IsDefault="True" Command="{Binding SaveCommand}"/>
<Button Grid.Column="2" Content="Cancel" Width="80"
Command="{Binding CancelCommand}"/>
IsCancel="True" Command="{Binding CancelCommand}"/>
</Grid>
</Border>

Expand Down
14 changes: 14 additions & 0 deletions src/Perpetuum.AdminTool/Views/NewRobotDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Perpetuum.AdminTool.NewItem;
using Perpetuum.AdminTool.ViewModels;

Expand All @@ -19,6 +21,18 @@ public NewRobotDialog(NewRobotDialogViewModel vm)
};
}

// Enter activates the default Save button without moving focus, so a TextBox bound with the
// default LostFocus trigger would still be holding an uncommitted value when Save runs. Push
// it to the source first. Multi-line boxes consume Enter themselves and are left alone.
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key != Key.Enter)
return;

if (Keyboard.FocusedElement is TextBox { AcceptsReturn: false } box)
box.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}

// Tab 1 — Basic
private void PickCategoryMain_Click(object sender, RoutedEventArgs e)
{
Expand Down
Loading