How to determine the type of object and tag

I am new to Windows Phone 7. I pressed one button and got:

private void button1_click(object sender, RoutedEventArgs e)
{

}

Is it possible to get the tag property and type of the sender object?

+3
source share
1 answer

You can get Type with GetType () :

sender.GetType();

If you want to use it as a button, you can do it.

var myButton = sender as Button;
if(myButton != null)
    var buttonTag = myButton.Tag;

Using asinstead (Button)sendermeans that instead of throwing an exception, if it cannot be selected as a button, it simply returns null. Then we can check if it is null and, if it is not null, we can access the Tag property.

+6
source

All Articles