获取当前按钮的内容

时间:2014-08-30 07:35:58

标签: c# xaml windows-phone-8

<Button Name="btn1" Content="1" HorizontalAlignment="Left" Margin="13,127,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<Button Name="btn2" Content="2" HorizontalAlignment="Left" Margin="135,124,0,0" VerticalAlignment="Top" Click="Button_Click"/>

如何通过一次函数调用获取当前按钮的内容?

1 个答案:

答案 0 :(得分:3)

试试这个:

private void Button_Click(object sender, RoutedEventArgs e)
{
    Button obj = (Button)sender;
    MessageBox.Show(obj.Content.ToString());
}