WPF rotate canvas

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.
 
J

jacky kwok

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>
 
M

moondaddy

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.
 
M

moondaddy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top