Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a MatrixTransform for any Transform

I'm working within the WPF stack, and I'd like to be able to get a MatrixTransform for any Transform. According to the link here, it doesn't seem that MatrixTransform is a base class but rather a sibling to the other Transform types. However, all normal graphics transforms should boil down to a MatrixTransform. Are there any shortcuts for this? Maybe something like hidden cast operators to take any transform to a MatrixTransform?

like image 986
J Trana Avatar asked Nov 23 '11 04:11

J Trana


1 Answers

The base class of TranslateTransform, MatrixTransform, etc. is the abstract class Transform.

The Transform class exposes a Value property of type Matrix. The MatrixTransform class has a constructor that takes a Matrix. So to get the general MatrixTransform corresponding to an existing LayoutTransform of a FrameworkElement you can use code like this:

var transform = new MatrixTransform(element.LayoutTransform.Value);
like image 67
Rick Sladkey Avatar answered Sep 19 '22 06:09

Rick Sladkey