私は、誰かが私が比較的単純な問題であると思っていたことを助けてくれることを願っています。DoubleAnimationからターゲットコントロールを取得するWPFでイベントを完了しましたか?
私は、DoubleAnimationオブジェクトを使用してコード内にフェードアウトアニメーションを設定しています。それはイメージをフェードアウトし、完了したらCompletedイベントを発生させます。
フェードアウトアニメーションがイベントハンドラ内から適用されたコントロールの名前を取得したいが、私は方法を見つけることができない。
助けてください。ありがとう。
DispatcherTimer timer = new DispatcherTimer();
public MainWindow()
{
InitializeComponent();
image1.Visibility = System.Windows.Visibility.Visible;
image2.Visibility = System.Windows.Visibility.Collapsed;
timer.Interval = TimeSpan.FromSeconds(2);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void FadeOut(UIElement element)
{
DoubleAnimation FadeOut = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.5)));
FadeOut.Completed += new EventHandler(FadeOut_Completed);
element.BeginAnimation(OpacityProperty, FadeOut);
}
void FadeOut_Completed(object sender, EventArgs e)
{
// How to find out which control was targeted?
}
void timer_Tick(object sender, EventArgs e)
{
if (image1.Visibility == System.Windows.Visibility.Visible)
{
FadeOut(image1);
//image1.Visibility = System.Windows.Visibility.Collapsed;
//image2.Visibility = System.Windows.Visibility.Visible;
}
}
送信者ですか?このアニメーションのターゲットは明示的に設定されていないので、それが正常に送信された場合は – EvAlex
どうすればターゲットを明示的に設定できますか? PS。タイマーティックイベントを含むようにコードを更新しました。 – Tas
私は幾分間違っていましたが、解決策を見つけました。私の答えを参照 – EvAlex