0

HubSectionWindows 8.1 XAML/C# コントロールの背景画像をフェードアウトおよびフェードインする方法はありますか?

実際、私はこのXAMLコードを持っています:

<HubSection x:Name="Section0" Width="700" Margin="0,0,80,0" VerticalContentAlignment="Bottom">
   <HubSection.Background>
      <ImageBrush x:Name="Section0Background" ImageSource="/Assets/images/img1.jpg" Stretch="UniformToFill" />
   </HubSection.Background>
   <!--... some other markup ... -->
</HubSection>

10秒ごとに背景画像をフェードアウトしたい->画像を変更->再びフェードイン。

次のコード行を使用してこれを試しました。

Storyboard storyboard = new Storyboard();

DoubleAnimation animation = new DoubleAnimation();
animation.From = 1.0;
animation.To = 0.0;
animation.BeginTime = TimeSpan.FromSeconds(0);
animation.Duration = new Duration(TimeSpan.FromMilliseconds(200));

storyboard.Children.Add(animation);

Storyboard.SetTargetProperty(animation, "Opacity");
Storyboard.SetTarget(animation, Section0Background);

storyboard.Completed += storyboard_Completed; // --> on complete change image and fade in
storyboard.Begin();

しかし、これはうまくいきません。絵コンテが完成すると、画像は変化しますが、フェード効果はありません。 「アニメート可能」ではありませんか?HubSection.Background

4

1 に答える 1

1

コントロールが HubSection に入ると、コード ビハインドでコントロールを参照できるとは思えません。したがって、Storyboard.SetTarget はおそらく、Section0Background を参照しようとする原因です。このアニメーションのほとんどはおそらく XAML で作成できますが、画像を変更するには、ImageBrush の ImageSource プロパティをバインドし、HubSection の DataContext を設定する必要があります。

次に、ストーリーボードの完了イベントが発生したときのコード ビハインドで、ImageSource プロパティを再バインドするイベントを発生させる ViewModel (HubSection の DataContext として設定されている) を変更します。

要約すると、HubSections でコントロールを参照することはできません。プロパティは、データ バインディングを通じてのみ変更できます。

同様の質問/回答があります。

于 2013-12-16T03:51:04.540 に答える