-1

WPF アプリケーション内には、サーバーから入力される IObservable があります。新しい .NET 4.5 機能 (async、await) に移行しているため、最初は画像なしで ReturnItems のみを読み込み、ダウンロードが成功した後、Parallel.Foreach() を使用して関連する画像も読み込みます。

各アイテムの画像ダウンロードが完了すると、byte[] が ReturnItems CoverImage プロパティに割り当てられ、UI DataTemplate s Image 要素からもこのプロパティにバインドされます。

私が達成したいのは、この画像の読み込みプロセスをアニメーション化して、画像の読み込みが完了すると、何もないアニメーションから何らかのフェードインが発生するようにすることです。できればストーリーボードを使いたいです。

4

1 に答える 1

0

画像のソースを設定する前はnull、つまり、空の配列などではないと思います。その場合は、画像に次のスタイルを使用します。

<Style x:Key="StyleImageFadeIn"
       TargetType="{x:Type Image}">
    <Setter Property="Opacity"
            Value="0" />
    <Style.Triggers>
        <!--Sets visibility to Collapsed if Source is null - this will cause IsVisible to be false-->
        <Trigger Property="Source"
                 Value="{x:Null}">
            <Setter Property="Visibility"
                    Value="Collapsed" />
        </Trigger>
        <!--Fades-in the image when it becomes visible-->
        <Trigger Property="IsVisible" Value="True">
            <Trigger.EnterActions>
                <BeginStoryboard>
                    <BeginStoryboard.Storyboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                             To="1"
                                             Duration="0:0:1"/>
                        </Storyboard>
                    </BeginStoryboard.Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
            <!--This (ExitActions) is only necessary if the image is "loosing" its source at run-time-->
            <Trigger.ExitActions>
                <BeginStoryboard>
                    <BeginStoryboard.Storyboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                             To="0"
                                             Duration="0:0:0" />
                        </Storyboard>
                    </BeginStoryboard.Storyboard>
                </BeginStoryboard>
            </Trigger.ExitActions>
        </Trigger>
    </Style.Triggers>
</Style>
于 2013-01-10T10:19:41.753 に答える