We use controls all the time for example a button and sometimes we may want to add some custom properties to that button. For example numberOfTimesClicked etc. I am currently working with GridViewColumnHeader and I would like to add the property columnIndex to that class. I know I can keep track of the columns with other methods but I am just curios to know if we can add extra properties to classes. For example I was thinking about inheritance. If I create a new class and inherit from the class that I want to add new properties (in my case GridViewColumnHeader) then I think that should work but for some reason I get errors in my code whenever I do something like:
private class MyGridViewColumnHeader : GridViewColumnHeader
{
public int propertyThatIWantToAdd { get; set; }
}
from now on if I instantiate objects from MyGridViewColumnHeader class instead of GridViewColumnHeader class I get errors. What is wrong with using inheritance to achieve this?
Instead of casting the
senderobject useAnd do your work on that object. If you need to know what is inside the
RoutedEventArgshave a look on MSDN