2012-01-05 5 views
2

Silverlightで画像を「フェードイン」する方法について誰かが私にリソースを教えてもらえますか?基本的には、Webサービスから返されるアイテムのリストボックスがあり、画像の読み込みに時間がかかることがありますので、ダウンロードしていくうちにフェードインしたいと思いました。私はこの効果のためにストーリーボードが必要かもしれないと読んだ。これは最善のルートですか、代替手段がありますか?ロードシルバーライトで画像をフェードインする方法は?

答えて

2

私には何の選択肢もありません。ストーリーボードは最善のルートです。画像の不透明度を0から100までアニメーション化できます。

StoryboardをUserControl()またはApp.xamlのリソースに配置します。

は、その後、あなたのOnOpenedイベント(あなたがコメントで述べたように)で: http://www.codeproject.com/KB/silverlight/AgDynAnimations.aspx とストーリーボードを開始:

protected void OnOpened(object sender, EventArgs e) 
{ 
    // params might be incorrect 
    this.fadeInStoryBoard.Stop(); 
    // your image controls will need x:names set 
    this.fadeInAnimation.SetValue(Storyboard.TargetNameProperty, ((Image)sender).Name); 
    this.fadeInStoryBoard.Start(); 
} 

例のストーリーボードからですhttp://blogs.msdn.com/b/silverlight_sdk/archive/2008/03/26/target-multiple-objects-properties-with-one-animation-silverlight.aspx

+0

任意のアイデアへの初期の不透明度を設定する必要がありますか? OnOpenedイベントの中でアニメーションを再生する必要があることはわかっています。 – loyalpenguin

2

はここですタスクを実行するユーティリティ関数

private void FadeIn(UIElement uilelement) 
{ 
    uilelement.Opacity = 0.0; 
    uilelement.Visibility = Visibility = Visibility.Visible; 
    var timeline = new DoubleAnimation() { To = 1.0, Duration =TimeSpan.FromSeconds(3.0) }; 
    Storyboard.SetTarget(timeline, uilelement); 
    Storyboard.SetTargetProperty(timeline, new PropertyPath(UIElement.OpacityProperty)); 
    var sb = new Storyboard(); 
    sb.Children.Add(timeline); 
    sb.Begin(); 
} 

function void image1_Opened(object sender, EventArgs e) 
{ 
    FadeIn(sender as Image); 
} 

あなたはどのように画像にこれを適用するために折りたたまへのイメージを設定し、または0

<Image Source="{Binding ImagePath}" 
     Name="image1" 
     Visibility="Collapsed" 
     ImageOpened="image1_ImageOpened" /> 
関連する問題