2011-08-14 4 views
0

1つのオブジェクトが1つのグリッドセルから別のグリッドセルに移動するアニメーションを作りたいと思います。私はオブジェクトの位置を計算しようとしましたが、うまくいきませんでした。関心のある人なら、コードは次のとおりです。グリッドセルのアニメーション

Point locationToScreen = (((e.Source as Button).Content as Viewbox).Child as Label).PointToScreen(new Point(0, 0)); 

PresentationSource source = PresentationSource.FromVisual((((e.Source as Button).Content as Viewbox).Child as Label)); 
Point pt = source.CompositionTarget.TransformFromDevice.Transform(locationToScreen); 

Point a = (letters.Children[_words[_index].Index] as TextBlock).PointToScreen(new Point(0, 0)); 

PresentationSource sos = PresentationSource.FromVisual((letters.Children[_words[_index].Index] as TextBlock)); 
Point pt2 = sos.CompositionTarget.TransformFromDevice.Transform(a); 

TranslateTransform tt = new TranslateTransform(); 
(((e.Source as Button).Content as Viewbox).Child as Label).RenderTransform = tt; 
DoubleAnimation da1 = new DoubleAnimation(0, -(pt.Y - pt2.Y)/2, new Duration(TimeSpan.FromSeconds(1))); 
DoubleAnimation da2 = new DoubleAnimation(0, -(pt.X - pt2.X)/2, new Duration(TimeSpan.FromSeconds(1))); 
tt.BeginAnimation(TranslateTransform.YProperty, da1); 
tt.BeginAnimation(TranslateTransform.XProperty, da2); 

どうすればよいですか?オブジェクトをあるコンテナから別のコンテナに移動する簡単な方法はありますか?

答えて

1

あなたは間違いなく、より良いアニメーションが、その要素が消え、SourceDestination終わった後、あなたが、Source要素とDestination要素までの移動の最上部に表示されます新しい UI要素を作成することを同時に、それを1000のオブジェクトのアニメーションのようなものを必要としない場合要素のプロパティは要求どおりに変更されます。

私は個人的にXAMLを使用する方が簡単だと思いますが、私には明らかです。 Animation XAML

TextBlockタグの下にアニメーションを宣言して、それを変更して希望の瞬間にアニメーションを起動する依存プロパティにバインドします。

+0

はい、これは1つのオブジェクトに過ぎません。しかし、私は本当に "何らかの依存性プロパティにバインドする"と言ってどういうことを理解していないのですか?単純な例を教えてください。 –

関連する問題