gpt4 book ai didi

c# - 动画网格以移动或滑动到右侧 WPF

转载 作者:太空狗 更新时间:2023-10-29 21:09:23 25 4
gpt4 key购买 nike

我有一个包含元素的网格。我想移动所有这些元素,所以不能一起移动网格吗?这对我所看到的没有任何影响,我什至尝试过 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>

我的功能:

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

最佳答案

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

<Grid x:Name="HancockDetails" ...>  
<Grid.RenderTransform>
<TranslateTransform />
</Grid.RenderTransform>
</Grid>

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

Storyboard.SetTargetProperty(slide, 
new PropertyPath("RenderTransform.(TranslateTransform.X)"));

关于c# - 动画网格以移动或滑动到右侧 WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com