I have a simple application consisting of a Window containing a Canvas (rootCanvas). I am trying to add another Canvas (test) to this and apply different Transforms to the child canvas's LayoutTransform. This is all being done programmatically rather than using XAML.
Some transforms are working, whilst others are not as follows:
The code is given below:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Canvas rootCanvas = (Canvas)Application.Current.Windows[0].FindName("canvas1");
Canvas test = new Canvas();
test.Width = 10;
test.Height = 10;
test.Background = Brushes.Aqua;
// this works
//test.LayoutTransform = new RotateTransform(45);
// this doesn't
//test.LayoutTransform = new TranslateTransform(40, 40);
// only the rotate part of this works
Matrix matrix = new Matrix();
matrix.Rotate(45);
matrix.Translate(40, 40);
test.LayoutTransform = new MatrixTransform(matrix);
rootCanvas.Children.Add(test);
}
}
I would be extremely grateful if someone could explain what I am doing wrong here, as I do not understand why translations do not seem to be working as I would expect.
Thanks in advance,
Wibbs
Please read the remarks in FrameworkElement.LayoutTransform Property.
However, LayoutTransform ignores TranslateTransform operations.
Use UIElement.RenderTransform Property for applying a TranslateTransform
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With