スライド ショーのように画像ソースを変更するときに、FadeIn と FadeOut の画像を実装するにはどうすればよいですか。私の画像はローカルとウェブから読み込まれ、その数は可変です。ありがとうございました
6455 次
2 に答える
13
Opacity
プロパティを 0 にアニメートして画像をフェードアウトし、プロパティを設定してSource
、最後に不透明度を 1 に戻す拡張メソッドを作成できます。
public static void ChangeSource(
this Image image, ImageSource source, TimeSpan fadeOutTime, TimeSpan fadeInTime)
{
var fadeInAnimation = new DoubleAnimation(1d, fadeInTime);
if (image.Source != null)
{
var fadeOutAnimation = new DoubleAnimation(0d, fadeOutTime);
fadeOutAnimation.Completed += (o, e) =>
{
image.Source = source;
image.BeginAnimation(Image.OpacityProperty, fadeInAnimation);
};
image.BeginAnimation(Image.OpacityProperty, fadeOutAnimation);
}
else
{
image.Opacity = 0d;
image.Source = source;
image.BeginAnimation(Image.OpacityProperty, fadeInAnimation);
}
}
于 2013-10-31T13:44:27.217 に答える