Animate a grid to move or slide to the right WPF

c#, visual-studio-2010, wpf, xaml

Solution

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)"));

Problem

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(); ```

Original source