2016-08-17 5 views
0

現在、私はWindows.UI.Composition名前空間で少し実験しています。ExpressionAnimationを使用してボタンのアニメーションが表示されない

var offsetAnimation = compositor.CreateExpressionAnimation(); 
offsetAnimation.SetReferenceParameter("ps", _propertySet); 
offsetAnimation.Expression = "ps.myValue"; 

var buttonVisual = ElementCompositionPreview.GetElementVisual(testButton); 
buttonVisual .StartAnimation("Offset.X", offsetAnimation); 

_propertySetページに特異的である、myValue他の方法から更新/追加されます。

ボタンのコード:

<Button x:Name="testButton" Background="Red" /> 

問題は、ボタンのOffsetが変化しないということである代わりに、何も起こりません。しかし、OpacityまたはScaleのいずれかのプロパティをアニメートすると、同じ式が機能しています。私はWebViewを私のページにも追加しました。ここにはOffsetが正しくアニメーションされています。

答えて

0

オフセットは、タイプです。System.Numerics.Vector3です。アニメーションを作成する簡単な方法は、Vector3KeyFrameAnimationを使用することです。あなたがExpressionAnimation.SetReferenceParameterを使用する場合

var newOffset = new Vector3(newValueX, newValueY, newValuez); 
var offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); 
offsetAnimation.Duration = TimeSpan.FromSeconds(1); 
offsetAnimation.InsertKeyFrame(1f, newOffset); 

var buttonVisual = ElementCompositionPreview.GetElementVisual(testButton); 
buttonVisual .StartAnimation("Offset", offsetAnimation); 
+0

* KeyFrameAnimation *は解決策ではありません。「myValue」はユーザーの入力に基づいています。 –

+0

ユーザー入力に基づいて、** newOffset **オブジェクトを作成できます。 offsetAnimationを作成してキャッシュします。 ** newOffset **を作成すると、 'offsetAnimation.InsertKeyFrame(1f、newOffset);を呼び出してキーフレームを設定できます。 – Ratish

0

変数_propertySetCompositionObjectクラスから派生する必要があります。 _anotherVisual.Offset.Xを設定できますが、一部のフロートフィールドを設定することはできません。

視覚オフセットをある値にアニメートする場合は、暗黙のアニメーションを実装します。

関連する問題