This is the WPF calculator code.
Example method for the button (btn 1)
private void btn1_Click(object sender, RoutedEventArgs e) { KeyAll(1); } //----------------------------------------------------------------- void KeyAll(int enter) { if (operation == "") { number1 = (number1 * 10) + enter; txtDisplay.Text = number1.ToString(); } else { number2 = (number2 * 10) + enter; txtDisplay.Text = number2.ToString(); } } //-------------------------------------------------------------------- private void Grid_PreviewKeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.NumPad1: KeyAll(1); break; //и так далее I tried through (KeyDown through PreviewKeyDown) I tried to subscribe to the event both to the button and at the Grid level.
I click the mouse - it works. I click on the keyboard - it works, but only if before that you click on any digit with the mouse.
<Button x:Name="btn1" Grid.Row="4" Grid.Column="0" FontSize="30" Click="btn1_Click" >1</Button>or at the level<Grid.ColumnDefinitions> <ColumnDefinition/>In general, I tried it there and there. I understand the focus on txtDisply, but I don’t understand how to transfer it to button 1 for example. ` - j. AtistoGrid.PreviewKeyDown, but toWindow.PreviewKeyDown- Andrey NOP