我正在尝试使用Storyboard类从代码中进行一些动画操作。但是发现没有ThicknessAnimation类可用,我还尝试使用Blend来构建Storyboard,但是效果不佳。动画会直接跳转到新值,没有流畅的动画效果。
更新:我尝试使用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();
}
Xaml:
<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>