You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.6 KiB

<Window x:Class="CommandPatternSample.MainWindow"
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:local="clr-namespace:CommandPatternSample"
xmlns:vm="clr-namespace:CommandPatternSample.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="400"
FocusManager.FocusedElement="{Binding ElementName=tbName}">
<Window.DataContext>
<vm:EmpViewModel/>
</Window.DataContext>
<StackPanel Margin="10">
<TextBlock Text="Enter the employee name."/>
<TextBox x:Name="tbName"
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}"/>
<ListBox x:Name="lbEmps"
ItemsSource="{Binding Emps}"
SelectedItem="{Binding SelectedEmp}"
DisplayMemberPath="Name"/>
<Label Height="40" Width="150" HorizontalAlignment="Center"
Content="{Binding ElementName=lbEmps, Path=SelectedItem}"/>
</StackPanel>
</Window>