所以我創建的鬧鐘在其中使用了一個動畫,並且我終於明白了這一點,並重新設置了自己的能力。但現在第一次啓動時,如果再次輸入警報喚醒時間,則警報將熄滅2次,如果我第三次輸入警報,它也會執行相同的操作,只是這次警報熄滅了3次。如果語句無限循環
下面是代碼:
private void dispatcherTimer1_Tick(object sender, EventArgs e)
{
label1.Content = DateTime.Now.ToString("hh") + ":" + DateTime.Now.ToString("mm") + " " + DateTime.Now.ToString("t"+2);
}
//ALARM CLOCK
private void dispatcherTimer2_Tick(object sender, EventArgs e)
{
OpacityLower.Duration = new Duration(TimeSpan.FromSeconds(3));
OpacityLower.AutoReverse = false;
OpacityLower.To = 0.0;
OpacityRaise.Duration = new Duration(TimeSpan.FromSeconds(3));
OpacityRaise.AutoReverse = false;
OpacityRaise.To = 100.0;
//Alarm settings
if (label1.Content.Equals(label2.Content))
{
//ANIMATION
OpacityLower.Completed += (s, d) =>
{
//Actual Wake Up Call, of which i took out so nobody could get the code, also it not relevant to this,
TimeOfDayCB.Text = "";
HourAlarmCB.Text = "";
MinuteAlarmCB.Text = "";
label2.Content = null;
dispatcherTimer2.Stop();
label2.BeginAnimation(Label.OpacityProperty, OpacityRaise);
OpacityRaise.Completed += (z, c) =>
{
TimeOfDayCB.Text = "";
HourAlarmCB.Text = "";
MinuteAlarmCB.Text = "";
label2.Content = null;
dispatcherTimer2.Stop();
};
};
label2.BeginAnimation(Label.OpacityProperty, OpacityLower);
dispatcherTimer2.Stop();
}
}
所以看到我的代碼,如果你能告訴我,爲什麼發生這種情況,並請忽略代碼是如何寫的不好後......(我在做一個測試階段這相當於凌亂的編碼)。
雅是我認爲問題會在哪裏。所以要解決這個問題我該怎麼做Opacity.Lowered.Completed + = ???或Opacity.Lowered.Completed;此外,Opacity.Raised事件也會執行相同的操作... –
將所有這些事件從'dispatcherTimer2_Tick'方法移出並進入應用程序啓動。 –
不幸的是,並沒有解決這個問題。它仍然發射兩次,我認爲他們自己的標籤沒有通過 –