key binding

This commit is contained in:
2023-07-10 17:50:09 +09:00
parent 3d26bffc07
commit d3677f99c4
13 changed files with 464 additions and 2 deletions

View File

@@ -6,7 +6,8 @@
xmlns:local="clr-namespace:CommandPatternSample"
xmlns:vm="clr-namespace:CommandPatternSample.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="400">
Title="MainWindow" Height="300" Width="400"
FocusManager.FocusedElement="{Binding ElementName=tbName}">
<Window.DataContext>
<vm:EmpViewModel/>
</Window.DataContext>
@@ -14,7 +15,13 @@
<StackPanel Margin="10">
<TextBlock Text="Enter the employee name."/>
<TextBox x:Name="tbName"
Text="{Binding SelectedEmp.Name}"/>
Text="{Binding SelectedEmp.Name}">
<TextBox.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding AddEmpCommand}"
CommandParameter="{Binding ElementName=tbName,Path=Text}"/>
</TextBox.InputBindings>
</TextBox>
<Button Content="Add"
Command="{Binding AddEmpCommand}"
CommandParameter="{Binding ElementName=tbName, Path=Text}"/>