views:

114

answers:

1
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");
       }

   }

How can I use something like sender.Text to see what the .Text is of the clicked button?

+4  A: 

Something like the pseudo code below:

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");
   }
}
Rowland Shaw
Just one remark : in Silverlight, Button doesn't have a Text property, it has a Content property instead (because the content can be anything, not just text)
Thomas Levesque
Now less pseudo, more code (I was also missing the brackets from the if - the cast if the important bit, of course...
Rowland Shaw