为网格设置动画以移动或滑动到右边的WPF

use*_*991 6 c# wpf xaml visual-studio-2010

我有一个包含元素的网格.我想移动所有这些元素,所以不可能只将网格一起移动吗?这对我所看到的没有任何影响,我甚至尝试过ScaleX等等.

<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>
Run Code Online (Sandbox Code Playgroud)

我的功能:

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();
Run Code Online (Sandbox Code Playgroud)

McG*_*gle 6

您需要先RenderTransform在标记中添加,否则运行时无法找到它:

<Grid x:Name="HancockDetails" ...>  
    <Grid.RenderTransform>
        <TranslateTransform />
    </Grid.RenderTransform>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我假设您要使用TranslateTransform,而不是ScaleTransform,因为目标是将网格滑过,而不是调整大小?

Storyboard.SetTargetProperty(slide, 
    new PropertyPath("RenderTransform.(TranslateTransform.X)"));
Run Code Online (Sandbox Code Playgroud)


Ant*_*ell 5

而不是试图手工创建故事板,这是更容易使用Expression Blend.它是一个免费的设计工具,与Visual Studio相得益彰.您正在解释的故事板将需要30秒才能完成,并且没有代码.然后,当你想要它运行它只是StoryBoardName.Begin()

为了方便吗?这是一种资源.http://msdn.microsoft.com/en-us/expression/cc197141.aspx

  • @Nitesh你在说什么?Blend是一种优秀的开发工具.许多专业人士都知道,工程师不是UI专家.因此,当您必须同时进行代码和设计时,通常设计就会变得简短.如果您可以解决问题的一半(代码),那么您可以专注于看起来正确的问题.Expression Blend是一个很棒的工具. (2认同)