J Trana
J Trana

Reputation: 2200

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?

Upvotes: 7

Views: 1922

Answers (1)

Rick Sladkey
Rick Sladkey

Reputation: 34240

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

Upvotes: 8

Related Questions