Есть окно-форма авторизации, 2 TextBox и кнопка Login, для этой формы нужно сделать экранную клавиатуру, которая будет вводить данные тот TextBox, на который нажали. Как это можно сделать на WPF, в рамках паттерна MVVM?
View:
<UserControl x:Class="PadVol2.Views.Pages.RegUserPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:PadVol2.Views.Pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Viewbox>
<StackPanel Orientation="Horizontal" Margin="50">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Номер пользователя:" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="White" Margin="0,0,5,5" Height="16" Width="118" />
<TextBox x:Name="login" Text="{Binding UID}" Width="100" HorizontalAlignment="Left" VerticalAlignment="Bottom" Grid.Column="1" Margin="5,0,0,5" Height="18" MaxLength="2"/>
<TextBlock Text="Пароль:" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Row="1" Foreground="White" Margin="0,5,5,0" Height="16" Width="44" />
<PasswordBox Name="passwordBox" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1" Grid.Row="1" Margin="5,5,0,0" Height="18"/>
<Button Command="{Binding Command}" CommandParameter="{Binding ElementName=passwordBox}" Content="Войти" Grid.Column="1" Grid.Row="1" Width="75" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="30,28,0,0" />
</Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="1" Height="40" Content="1" Margin="2" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="2" Height="40" Content="2" Margin="2" Grid.Column="1" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="3" Height="40" Content="3" Margin="2" Grid.Column="2" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="4" Height="40" Content="4" Margin="2" Grid.Row="1" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="5" Height="40" Content="5" Margin="2" Grid.Row="1" Grid.Column="1" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="6" Height="40" Content="6" Margin="2" Grid.Row="1" Grid.Column="2" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="7" Height="40" Content="7" Margin="2" Grid.Row="2" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="8" Height="40" Content="8" Margin="2" Grid.Row="2" Grid.Column="1" FontSize="20" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="9" Height="40" Content="9" Margin="2" Grid.Row="2" Grid.Column="2" FontSize="20" />
<Button Width="40" Command="{Binding DelLogin}" Height="40" Content="Удалить" Margin="2" Grid.Row="3" FontSize="8" />
<Button Width="40" Command="{Binding AddCharLogin}" CommandParameter="0" Height="40" Content="0" Margin="2" Grid.Row="3" Grid.Column="1" FontSize="20" />
<Button Width="40" Command="{Binding ClearLogin}" Height="40" Content="Очистить" Margin="2" Grid.Row="3" Grid.Column="2" FontSize="8" />
</Grid>
</StackPanel>
</Viewbox>
ViewModel:
class RegUserPageVM :ViewModelBase, IPageViewModel
{
public string UID { get; set; } = "";
public string Password { get; set; }
public ICommand Command { get; set; }
public ICommand AddCharLogin
{
get
{
return new DelegateCommand<object>(x =>
{
UID += x.ToString();
}, CanAddCharLogin);
}
}
private bool CanAddCharLogin(object param)
{
return this.UID.Length < 2;
}
public ICommand DelLogin
{
get
{
return new DelegateCommand(() =>
{
if (UID.Length > 0)
UID = UID.Substring(0, UID.Length - 1);
});
}
}
public ICommand ClearLogin
{
get
{
return new DelegateCommand(() =>
{
UID = "";
});
}
}
}