MatrixTransforms in WPF


MatrixTransform is used to create custom 2D transform. MatrixTranform generates by using Matrix class which inherits from System.Windows.Media and it represents 3x3 affine transformation matrix.

Basically Matrix class is 3x3 matrix and it looks like as shown below.

                        

The last column values are fixed and first two columns we can set as per our requirements through Matrix type or through MatrixTransform.

Let’s discuss the MatrixTransform with simple example. Open Microsoft Visual Studio 2013 => Create WPF application and name it as MatrixTransformExp.

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <Grid>

        <Button Grid.Row="5" Grid.Column="1" Background="AntiqueWhite"  Content="Matrix">

            <Button.LayoutTransform>

                <MatrixTransform Matrix="1,2,15,5,10,3"/>

            </Button.LayoutTransform>

        </Button>

    </Grid>

</Window>

 

As shown above we applies the MatrixTransform for the button.