How can I check the .Text property of the sender object in my event?

private void NuestroButton1_Click(object sender, RoutedEventArgs e)
   {
       if //the sender .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 of the button is pressed?

+2


source to share


1 answer


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

      

+6


source







All Articles