我正在尝试使用 Storyboard 类从代码中制作一些动画。没有 ThicknessAnimation 类。而且我还尝试使用 Blend 构建故事板,它在那里不起作用。它只是直接跳转到新值,没有流畅的动画。
更新:我尝试使用 TranslateX 转换。但是当我在图像上使用它时,图像会被剪裁。我正在尝试做的是在一个小网格内非常缓慢地为大图像设置动画,因此它具有这种效果(类似于 Zune 和 Windows Phone Gallery 中的效果)。一旦图像打开我开始动画,这是我的代码:
private void Image_ImageOpened_1(object sender, RoutedEventArgs e)
{
var img = sender as Image;
Storyboard sb = new Storyboard();
var doubleAnimationx = new DoubleAnimation() { To = -100, SpeedRatio = 0.1, From = 0 };
Storyboard.SetTarget(doubleAnimationx, img);
Storyboard.SetTargetProperty(doubleAnimationx, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
sb.Children.Add(doubleAnimationx);
sb.Begin();
}
xml:
<Grid IsSwipeEnabled="True" ItemsSource="{Binding Source={StaticResource cvs1}}" ItemClick="ItemsGridView_ItemClick_1"
x:Name="ItemsGridView" Margin="50,20,116,46" SelectionMode="None" IsItemClickEnabled="True"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Grouped Items">
<Grid.ItemTemplate>
<DataTemplate>
<Grid Height="250" VariableSizedWrapGrid.ColumnSpan="{Binding ColumnSpan}" Margin="2">
<Image ImageOpened="Image_ImageOpened_1" Stretch="UniformToFill" Source="{Binding ImageHQ}" >
<Image.RenderTransform>
<CompositeTransform />
</Image.RenderTransform>
</Image>
<StackPanel VerticalAlignment="Bottom" Background="#AA000000">
<TextBlock Margin="5,5,5,0" FontSize="26" Text="{Binding Name,Mode=OneWay}" FontFamily="Arial Black" />
<TextBlock Margin="5,0,5,5" FontSize="24" Text="{Binding Section,Mode=OneWay}" Foreground="{Binding SectionColor,Mode=OneWay}" />
</StackPanel>
</Grid>
</DataTemplate>
</Grid.ItemTemplate>
</Grid>