Skip to main content

Microsoft Silverlight

Answered Question How to assign two types of transforms in Canvas.RenderTransformRSS Feed

(0)

leafinwind
leafinwind

Member

Member

5 points

10 Posts

How to assign two types of transforms in Canvas.RenderTransform

Hi,

I am planning to do both rotation and translation of the same user control. That user control contains a canvas. What I did is set one rotateTransform in Canvas.RenderTransform. It seems that I can only set one transform. I tried to put two there as is in the following code. But it can not compile.

What can I do if I still want to have control of two transformation types on this usercontrol object? Thanks.

<UserControl x:Class="Brick"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="60" Height="30">
    <Canvas Height="30" Width="60" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="30,30,0,0">
        <Canvas.RenderTransform>
            <RotateTransform x:Name="rotateTransform" Angle="0"/>
            <TranslateTransform x:Name="translateTransform" X="1" Y="1" />
        </Canvas.RenderTransform>
        <Ellipse Height="30" Width="30" Canvas.Left="0" Canvas.Top="0" Fill="#FFD21B1B" Stroke="#FF000000"/>
        <Ellipse Height="30" Width="30" Canvas.Left="30" Canvas.Top="0" Fill="#FFF9E505" Stroke="#FF000000"/>
    </Canvas>
</UserControl>

Skyrunner
Skyrunner

Contributor

Contributor

2489 points

485 Posts

Silverlight MVP
Answered Question

Re: How to assign two types of transforms in Canvas.RenderTransform

You must use a <TransformGroup> markup inside RenderTransform.

HarshBardhan
HarshBar...

Star

Star

9908 points

1,719 Posts

Answered Question

Re: How to assign two types of transforms in Canvas.RenderTransform

Hi,

If you will add Transform group like given below it will work...You can add like this it will work.

<UserControl x:Class="Brick"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="60" Height="30">
    <Canvas Height="30" Width="60" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="30,30,0,0">
        <Canvas.RenderTransform>

< TransformGroup>
            <RotateTransform x:Name="rotateTransform" Angle="0"/>
            <TranslateTransform x:Name="translateTransform" X="1" Y="1" />

<TransformGroup>
        </Canvas.RenderTransform>
        <Ellipse Height="30" Width="30" Canvas.Left="0" Canvas.Top="0" Fill="#FFD21B1B" Stroke="#FF000000"/>
        <Ellipse Height="30" Width="30" Canvas.Left="30" Canvas.Top="0" Fill="#FFF9E505" Stroke="#FF000000"/>
    </Canvas>
</UserControl>

Mark as answer if this post answered your question.

Harsh Bardhan

leafinwind
leafinwind

Member

Member

5 points

10 Posts

Re: How to assign two types of transforms in Canvas.RenderTransform

It works! Thank you guys.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities