如何检查我的事件中发件人对象的.Text属性?

时间:2009-08-24 12:44:35

标签: c# silverlight events event-handling

private void NuestroButton1_Click(object sender, RoutedEventArgs e)
   {
       if //the sender's .Text/.Content is X
       {
            //Do something
            System.Windows.Browser.HtmlPage.Window.Alert("Hello World");
       }

   }

如何使用sender.Text之类的东西来查看点击按钮的.Text是什么?

1 个答案:

答案 0 :(得分:6)

类似下面的伪代码:

private void NuestroButton1_Click(object sender, RoutedEventArgs e)
{
   Button foo = sender as Button; // Cast to the type we're expecting it to be

   if( foo != null && foo.Content == "X" )
   {
        //Do something
        System.Windows.Browser.HtmlPage.Window.Alert("Hello World");
   }
}