3
我用這個代碼來製作動畫我的窗口:無法設置其動畫後的屬性在WPF
winLogin login = new winLogin();
login.Owner = this;
login.Show();
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = this.Left + ((this.Width - login.Width)/2);
da.AutoReverse = false;
da.Duration = new Duration(TimeSpan.FromSeconds(0.1));
login.BeginAnimation(Window.LeftProperty, da);
問題是,每當我設置窗口的Left
財產(動畫)後,它會瘋狂。
我使用此代碼來對齊子窗口始終在中心,但我使用動畫的窗口的Left
屬性無法正確更改。
private void Window_LocationChanged(object sender, EventArgs e)
{
foreach (Window win in this.OwnedWindows)
{
win.Top = this.Top + ((this.Height - win.Height)/2);
win.Left = this.Left + ((this.Width - win.Width)/2);
}
}
事實上,使用SetCurrentValue設置值會不會好嗎? NVM,當然動畫仍然會優先於HoldEnd。 – 2010-09-17 09:46:09
新的.NET 4 DependencyObject.SetCurrentValue用於在不影響數據綁定源值的情況下設置數據綁定DependencyProperties上的值。但是,您的Window.LeftProperty不是數據綁定。動畫直接設置屬性。 – bitbonk 2010-09-17 11:35:28