I've been working with C# and XAML and was wondering if there was any better way to access members of a class after casting them. This is an example of what I'd normally end up having to do:
private void MyButton_Clicked(object sender, RoutedEventtArgs e)
{
((PlaneProjection)((Button)sender).Projection).RotationX = 20;
}
Which'd rotate the button every time you clicked it, but with more complex actions I'd need more and more parentheses. I know I can use as which'd make it a little easier to read, but that'd still make it:
((sender as Button).Projection as PlaneProjection).RotationX = 20;
Which is still more parentheses than I'd like to have.
Am I doing this the long way or missing something? Or is this just the way it is and I'll have to deal with the possibility of harder to read code like this?