I have a button that I want to animate the basic concept is that when the button is clicked it "falls" into place from the left had of the screen. Once it is in position and clicked the button stands back up on the right side of the screen. The first animation works successfully but I can't get the second animation to rotate properly. I think I am confused about how either how the coordinate system is working or how and in what order WPF is rendering the control on the page and how the transforms and rotations are applied. Below is the .xaml and .xaml.cs files.
<Window x:Class="ScaleTest1.Window
1"
xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" WindowState="Maximized" Name="mainWin" SizeChanged="mainWin_SizeC
hanged" StateChanged="mainWin_Stat
eChanged">
<Window.Resources>
<Storyboard x:Key="storyBoardRotation"
Completed="Storyboard_Comp
leted">
<DoubleAnimation
Storyboard.TargetProperty=
"(Button.R
enderTrans
form).(Rot
ateTransfo
rm.Angle)"
From="0" To="90" Duration="0:0:2"
AutoReverse="False" />
</Storyboard>
<Storyboard x:Key="storyBoardRotation2
" >
<DoubleAnimation
Storyboard.TargetProperty=
"(Button.R
enderTrans
form).(Rot
ateTransfo
rm.Angle)"
From="90" To="180" Duration="0:0:5"
AutoReverse="False" />
</Storyboard>
</Window.Resources>
<Canvas>
<Button Margin="0,0,0,0" Name="ProgressBar1" HorizontalAlignment="Left"
Width="24" Height="150" VerticalAlignment="Top" Click="ProgressBar1_Click"
>
<Button.RenderTransform>
<RotateTransform x:Name="rtTest" Angle="0" />
</Button.RenderTransform>
</Button>
</Canvas>
</Window>
private void ProgressBar1_Click(object sender, RoutedEventArgs e)
{
Storyboard sb = new Storyboard();// = FindResource("storyBoardRo
tation") as Storyboard;
if (rtTest.Angle == 0)
{
ProgressBar1.RenderTransfo
rmOrigin = new Point(1,1);
//rtTest.CenterX = 24;
//rtTest.CenterY = 150;
sb = FindResource("storyBoardRo
tation") as Storyboard;
Storyboard.SetTargetName((
(DoubleAni
mation)sb.
Children[0
]), "ProgressBar1");
}
else if (rtTest.Angle == 90)
{
ProgressBar1.RenderTransfo
rmOrigin = new Point(1,0);
//rtTest.CenterX = 174
//rtTest.CenterY = 24;
sb = FindResource("storyBoardRo
tation2") as Storyboard;
Storyboard.SetTargetName((
(DoubleAni
mation)sb.
Children[0
]), "ProgressBar1");
}
sb.Begin(this);
}
I believe the problem is in understanding how either ot coordinate system is working and or the order in which transformations and rotations are appliend when the item is rendered.
If I change this line
ProgressBar1.RenderTransfo
rmOrigin = new Point(1,0);
in the else if to (.5, .5)
the the button seems to pop back to its orignial position (although rotated) and rotate around its centerpoint.
Can someone point me in the direction of understanding the rendering pipeline or the co-ordinate system please
Here is the .xaml and the and the code behind doesn't change right now
<Window x:Class="ScaleTest1.Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Name="mainWin" SizeChanged="mainWin_SizeC
<Window.Resources>
<Storyboard x:Key="storyBoardRotation"
<DoubleAnimation x:Name="rotateAnimation"
Storyboard.TargetProperty=
From="0" To="90" Duration="0:0:2"
AutoReverse="False" />
<DoubleAnimation Storyboard.TargetProperty=
From="0" To="0" Duration="0:0:2" AutoReverse="False"></Doub
<DoubleAnimation Storyboard.TargetProperty=
From="0" To="0" Duration="0:0:2" AutoReverse="False"></Doub
</Storyboard>
<Storyboard x:Key="storyBoardRotation2
<DoubleAnimation
Storyboard.TargetProperty=
From="90" To="180" Duration="0:0:2"
AutoReverse="False" Completed="DoubleAnimation
<DoubleAnimation Storyboard.TargetProperty=
From="150" To="150" Duration="0:0:2" AutoReverse="False"></Doub
<DoubleAnimation Storyboard.TargetProperty=
From="150" To="150" Duration="0:0:2" AutoReverse="False"></Doub
</Storyboard>
</Window.Resources>
<Grid>
<Rectangle Margin="0,0,0,0" Name="ProgressBar1" HorizontalAlignment="Left"
Fill="Black">
<Rectangle.RenderTransform
<TransformGroup>
<RotateTransform x:Name="rtTest" Angle="0" />
<TranslateTransform x:Name="txTest" X="0" Y="0"></TranslateTransform
</TransformGroup>
</Rectangle.RenderTransfor
</Rectangle>
<Button Margin="0,0,0,0" Name="ProgressBar1Button" HorizontalAlignment="Left"
<Button.RenderTransform>
<RotateTransform x:Name="rtTestButton" Angle="0" />
</Button.RenderTransform>
</Button>
<Button Margin="0,0,0,0" Name="ProgressBar2Button" HorizontalAlignment="Right
</Button>
</Grid>
</Window>