public void DigitButton_Click(object sender, RoutedEventArgs e) { this.Focus(); Button button = sender as Button; if (button != null && button.Tag is int) { OnDigitButtonPressed((int)button.Tag); } }