【发布时间】:2023-03-29 07:03:01
【问题描述】:
我正在使用这个 XAML 故事板来实现两个名为 ctlIMage 和 altImage 的图像之间的转换,定义如下:
<Image x:Name = "ctlImage" Grid.Column ="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="4" VerticalAlignment= "Stretch" HorizontalAlignment = "Stretch" Stretch = "Uniform" Opacity="0">
<Image.RenderTransform>
<CompositeTransform x:Name="image_Transform" ></CompositeTransform >
</Image.RenderTransform >
</Image>
<Image x:Name = "altImage" Grid.Column ="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="4" VerticalAlignment= "Stretch" HorizontalAlignment = "Stretch" Stretch = "Uniform" Opacity="0">
<Image.RenderTransform>
<CompositeTransform x:Name="altImage_Transform" ></CompositeTransform >
</Image.RenderTransform >
</Image>
<Storyboard x:Name="ctlImageFadeOut" Completed="SwapAltCtl">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ctlImage">
<EasingDoubleKeyFrame KeyTime="0" Value="1.0" />
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="image_Transform">
<EasingDoubleKeyFrame KeyTime="0" Value="1.0" />
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.5" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="image_Transform">
<EasingDoubleKeyFrame KeyTime="0" Value="1.0" />
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.5" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="altImage">
<EasingDoubleKeyFrame KeyTime="0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="1.0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
当我使用此代码播放动画时:
altImage.Opacity = 0;
altImage.Visibility = Visibility.Visible;
altImage.Source = await MainPlayList.GetCurrentImage((int)altImage.Height, (int)altImage.Width);
ctlImageFadeOut.Begin();
并使用此方法在动画结束时交换两个图像:
private async void SwapAltCtl(object sender, object e)
{
ctlImage.Opacity = 0;
image_Transform.ScaleX = 1;
image_Transform.ScaleY = 1;
ctlImage.Height = altImage.ActualHeight;
ctlImage.Width = altImage.ActualWidth;
ctlImage.Source = await MainPlayList.GetCurrentImage((int)ctlImage.Height, (int)ctlImage.Width);
ctlImage.Opacity = 1;
altImage.Opacity = 0;
altImage.Visibility = Visibility.Collapsed;
}
我最终得到了一个一半大小的 ctlImage,就像 ScaleX 和 ScaleY 在 XAML 情节提要之后不会重置。如您所见,我什至尝试将高度和宽度重置为已知值(已显示的备用图像)。
动画结束后如何重置图片?
谢谢!
【问题讨论】:
标签: c# image xaml uwp storyboard