WPF rotate canvas

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm working in a WPF windows application and am wondering if it's possible
to rotate a Canvas or user control derived from Canvas. I created a user
control which derives from Canvas and I need to rotate it 90, 180, and 270
degrees. Is this possible and if so, how would I do it? The use control
lives in a main canvas.

Thanks.
 
moondaddy said:
I'm working in a WPF windows application and am wondering if it's possible
to rotate a Canvas or user control derived from Canvas. I created a user
control which derives from Canvas and I need to rotate it 90, 180, and 270
degrees. Is this possible and if so, how would I do it? The use control
lives in a main canvas.

Thanks.

Is such Xaml suitable your requirement?


<Canvas Width="200" Height="200" Background="Yellow">
<Canvas.RenderTransform>
<RotateTransform CenterX="100" CenterY="100" Angle="60" />
</Canvas.RenderTransform>


<Button Canvas.Left="50" Canvas.Top="50" >button1</Button>
</Canvas>
 
Thanks. this works good, but I need to do it all from c#. Can you show an
example of this from the button click event? I see plenty of xaml examples
online, but no c# examples of working with RotateTransform.

Thanks again.
 
I found the answer:

void ButtonClick(object sender, RoutedEventArgs e)
{
canv1.RenderTransform = new RotateTransform(90,100,100);
}

moondaddy said:
Thanks. this works good, but I need to do it all from c#. Can you show
an example of this from the button click event? I see plenty of xaml
examples online, but no c# examples of working with RotateTransform.

Thanks again.
 
Back
Top