WPF如何知道多个按钮中当前按下的按钮 [英] WPF How to know the current button pressed among multiple buttons

查看:402
本文介绍了WPF如何知道多个按钮中当前按下的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个具有这样的内容1、2、3、4、5 ...的按钮。在 Click 事件中,所有按钮都使用相同的功能。

I am having multiple buttons with contents 1, 2, 3, 4, 5... like this. All buttons are using same function on Click event.

<Button Content="1" Height="30" Name="button1" Width="30" Click="calculate"/>
<Button Content="2" Height="30" Name="button2" Width="30" Click="calculate"/>
<Button Content="3" Height="30" Name="button3" Width="30" Click="calculate"/>
<Button Content="4" Height="30" Name="button4" Width="30" Click="calculate"/>
<Button Content="5" Height="30" Name="button5" Width="30" Click="calculate"/>

我怎么知道计算函数中按下了哪个按钮?我想从按下的按钮获取内容。

How could i know which button is pressed in calculate function ? I want to get the content from the button which is pressed.

private void calculate(object sender, RoutedEventArgs e)
        {

        }

谢谢。

Thank You.

推荐答案

您可以在函数中使用它获取内容属性-

You can get the content property using this in your function -

string content = (sender as Button).Content.ToString();

这篇关于WPF如何知道多个按钮中当前按下的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆