我想繪製一個簡單的圓形並通過編碼將其移動到X,Y軸上的定義位置。如何繪製一個圓形並將其作爲動畫在C#中移動WPF
例如;
在WPF窗口上會有2個按鈕,並且在0,0(x,y)上會有一個圓。當我點擊第一個按鈕時,它將轉到X = 150和Y = 40。但是形狀必須順利地進入。我的意思是我不希望它在當前位置失去知覺並出現在確定的位置上。我希望它去那裏。我應該怎麼做?你能解釋我的步驟嗎?如果可能的話,一些示例代碼?
更新的代碼:
int X = 0;
int Y = 0;
public bool inside = true;
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (inside)
{
DoubleAnimation animatex = new DoubleAnimation();
animatex.To = X++;
// animatex.Duration = new Duration(TimeSpan.FromSeconds(1));
// animatex.RepeatBehavior = RepeatBehavior.Forever;
el.BeginAnimation(Canvas.LeftProperty, animatex);
DoubleAnimation animatey = new DoubleAnimation();
animatey.To = Y++;
// animatey.RepeatBehavior = RepeatBehavior.Forever;
el.BeginAnimation(Canvas.TopProperty, animatey);
}
}
請參閱[這裏](http://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks)關於如何格式化代碼塊。你肯定不會永遠重複動畫,對吧?圓圈只需移動一次到目標位置。 – Clemens 2012-02-19 17:04:23
感謝您的解決方案。對於Clemens;實際上,我會改進代碼,並且我會製作4個箭頭,左右下移,每當我點擊其中一個時,它將一直持續下去,直到我用另一個按鈕結束移動。似乎我會在if循環中逐個增加animatex和animatey – Samet 2012-02-19 17:56:16
@ Ethicallogics或其他人:您能否檢查我在上面更新的代碼中所做的錯誤。我想繞圈移動,直到我改變if條件。但它不是那樣工作的。它每次點擊按鈕時都有效。 – Samet 2012-02-20 18:06:30