I have a grid with elements in it. I want to move all of those elements, so is it not possible to just move the grid all together? This isn't having any effect from what I'm seeing and I've tried even ScaleX and such as well.
<Grid x:Name="HancockDetails" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Grid.Column="1" RenderTransformOrigin="0.5,0.5">
<Rectangle HorizontalAlignment="Left" Height="100" Stroke="Black" VerticalAlignment="Top" Width="100"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Foreground="#FFF30000"/>
</Grid>
</Grid>
</s:ScatterViewItem>
My function:
Storyboard sb = new Storyboard();
DoubleAnimation slide = new DoubleAnimation();
slide.To = 3000.0;
slide.From = 0;
slide.Duration = new Duration(TimeSpan.FromMilliseconds(40.0));
// Set the target of the animation
Storyboard.SetTarget(slide,HancockDetails);
Storyboard.SetTargetProperty(slide, new PropertyPath("RenderTransform.(ScaleTransform.ScaleY)"));
// Kick the animation off
sb.Children.Add(slide);
sb.Begin();
You need to first add the RenderTransform
in the markup, otherwise the runtime can't find it:
<Grid x:Name="HancockDetails" ...>
<Grid.RenderTransform>
<TranslateTransform />
</Grid.RenderTransform>
</Grid>
I assume you want to use TranslateTransform
, and not ScaleTransform
, since the goal is to slide the grid over, not to resize it?
Storyboard.SetTargetProperty(slide,
new PropertyPath("RenderTransform.(TranslateTransform.X)"));
Instead of trying to create a storyboard by hand it is muuuuuuch easier to use Expression Blend. Its a free design tool that compliments Visual Studio. The storyboard you are explaining would take all of 30 seconds to make there and there would be no code. Then when you wanted it to run it would just be the StoryBoardName.Begin()
To easy right? Heres a resource. http://msdn.microsoft.com/en-us/expression/cc197141.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With