I have about 3-4 canvas controls and each contains about 750-1200 paths.
Users needs to make some transform to them and I use for that a global
Canvas SelectedCanvas;
Initially (in the constructor) SelectedCanvas takes the value of one my canvas controls.
SelectedCanvas = canvas1;
For the button wich rotates the canvas I use the next function:
private void RotateRightLayerButton_Click(object sender, RoutedEventArgs e)
{
if (SelectedCanvas.RenderTransform != null)
{
//method 1
CompositeTransform ct = canvas1.RenderTransform as CompositeTransform;
if (ct.Rotation == 360)//ct will return NullException
ct.Rotation = 0;
ct.Rotation += 30;
// method 2
TransformGroup tg = canvas1.RenderTransform as TransformGroup;
(tg.Children[0] as RotateTransform).Angle += 30;
//tg will return NullException
}
}
I also tried this link and
this link
but I need also to get the value of RenderTransform.
Am I doing something wrong? Thanks in advance!
The default value of the RenderTransform property is Transform.Identity. You have to apply a Transform, e.g. a RotateTransform, to your Canvas before you can manipulate it.
If you use a RotateTransform your code would have to look like this:
or: