How to Animate a Visual.TransformMatrix?










1















TransformMatrix documentation says "This property can be animated. Call CompositionObject.StartAnimation to associate it with a CompositionAnimation."



But I can't create a CompositionAnimation that can target it. I tried CreateQuaternionKeyframeAnimation and I tried CreateVector4KeyframeAnimation:



Visual visual = ElementCompositionPreview.GetElementVisual(myUIElement);
var animation = visual.Compositor.CreateVector4KeyFrameAnimation();
Vector4 v4 = Vector4.Transform(new Vector4(), myMatrix4x4);
animation.InsertKeyFrame(1f, v4);
animation.Duration = TimeSpan.FromMilliseconds(3000);
visual.StartAnimation(nameof(visual.TransformMatrix), animation);


Which throws "The expression output does not match animating property type" as one might expect. I don't know what else to try. Do I have to create 16 separate scalar animations, one for each matrix value? That seems a bit crazy.



EDIT:
So I tried to just roll my own and use 16 scalar animations like so:



for (int i = 5; i <= 20; i++)

int row = (i / 4);
int column = (i % 4);
if (column == 0) column = 4;
var matrixAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
var matrixEasing = visual.Compositor.CreateLinearEasingFunction();
matrixAnimation.InsertExpressionKeyFrame(1f, "this.FinalValue", matrixEasing);
matrixAnimation.Target = nameof(visual.TransformMatrix) + ".M" + row + column;
matrixAnimation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds);
visual.ImplicitAnimations[nameof(visual.TransformMatrix) + ".M" + row + column] = matrixAnimation;



So the implicit animations are created and all seems great. Then to my dismay I write the code to change the read/write M11- M44 properties which ought to trigger the implicit animation and I get a compiler error:




"Cannot modify the return value of 'Visual.TransformMatrix' because it
is not a variable".




And assigning it a new Matrix4x4 does not trigger the implicit animation.










share|improve this question



















  • 1





    I've helped you report this issue to the relevant team. They're investigating it.

    – Xavier Xie - MSFT
    Nov 16 '18 at 9:46











  • Just to clarify I'm using keyframe implicit animations. I heaven't dug in and learned expression animations yet, but perhaps that's the only way to do it.

    – Sean O'Neil
    Nov 16 '18 at 13:31















1















TransformMatrix documentation says "This property can be animated. Call CompositionObject.StartAnimation to associate it with a CompositionAnimation."



But I can't create a CompositionAnimation that can target it. I tried CreateQuaternionKeyframeAnimation and I tried CreateVector4KeyframeAnimation:



Visual visual = ElementCompositionPreview.GetElementVisual(myUIElement);
var animation = visual.Compositor.CreateVector4KeyFrameAnimation();
Vector4 v4 = Vector4.Transform(new Vector4(), myMatrix4x4);
animation.InsertKeyFrame(1f, v4);
animation.Duration = TimeSpan.FromMilliseconds(3000);
visual.StartAnimation(nameof(visual.TransformMatrix), animation);


Which throws "The expression output does not match animating property type" as one might expect. I don't know what else to try. Do I have to create 16 separate scalar animations, one for each matrix value? That seems a bit crazy.



EDIT:
So I tried to just roll my own and use 16 scalar animations like so:



for (int i = 5; i <= 20; i++)

int row = (i / 4);
int column = (i % 4);
if (column == 0) column = 4;
var matrixAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
var matrixEasing = visual.Compositor.CreateLinearEasingFunction();
matrixAnimation.InsertExpressionKeyFrame(1f, "this.FinalValue", matrixEasing);
matrixAnimation.Target = nameof(visual.TransformMatrix) + ".M" + row + column;
matrixAnimation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds);
visual.ImplicitAnimations[nameof(visual.TransformMatrix) + ".M" + row + column] = matrixAnimation;



So the implicit animations are created and all seems great. Then to my dismay I write the code to change the read/write M11- M44 properties which ought to trigger the implicit animation and I get a compiler error:




"Cannot modify the return value of 'Visual.TransformMatrix' because it
is not a variable".




And assigning it a new Matrix4x4 does not trigger the implicit animation.










share|improve this question



















  • 1





    I've helped you report this issue to the relevant team. They're investigating it.

    – Xavier Xie - MSFT
    Nov 16 '18 at 9:46











  • Just to clarify I'm using keyframe implicit animations. I heaven't dug in and learned expression animations yet, but perhaps that's the only way to do it.

    – Sean O'Neil
    Nov 16 '18 at 13:31













1












1








1








TransformMatrix documentation says "This property can be animated. Call CompositionObject.StartAnimation to associate it with a CompositionAnimation."



But I can't create a CompositionAnimation that can target it. I tried CreateQuaternionKeyframeAnimation and I tried CreateVector4KeyframeAnimation:



Visual visual = ElementCompositionPreview.GetElementVisual(myUIElement);
var animation = visual.Compositor.CreateVector4KeyFrameAnimation();
Vector4 v4 = Vector4.Transform(new Vector4(), myMatrix4x4);
animation.InsertKeyFrame(1f, v4);
animation.Duration = TimeSpan.FromMilliseconds(3000);
visual.StartAnimation(nameof(visual.TransformMatrix), animation);


Which throws "The expression output does not match animating property type" as one might expect. I don't know what else to try. Do I have to create 16 separate scalar animations, one for each matrix value? That seems a bit crazy.



EDIT:
So I tried to just roll my own and use 16 scalar animations like so:



for (int i = 5; i <= 20; i++)

int row = (i / 4);
int column = (i % 4);
if (column == 0) column = 4;
var matrixAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
var matrixEasing = visual.Compositor.CreateLinearEasingFunction();
matrixAnimation.InsertExpressionKeyFrame(1f, "this.FinalValue", matrixEasing);
matrixAnimation.Target = nameof(visual.TransformMatrix) + ".M" + row + column;
matrixAnimation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds);
visual.ImplicitAnimations[nameof(visual.TransformMatrix) + ".M" + row + column] = matrixAnimation;



So the implicit animations are created and all seems great. Then to my dismay I write the code to change the read/write M11- M44 properties which ought to trigger the implicit animation and I get a compiler error:




"Cannot modify the return value of 'Visual.TransformMatrix' because it
is not a variable".




And assigning it a new Matrix4x4 does not trigger the implicit animation.










share|improve this question
















TransformMatrix documentation says "This property can be animated. Call CompositionObject.StartAnimation to associate it with a CompositionAnimation."



But I can't create a CompositionAnimation that can target it. I tried CreateQuaternionKeyframeAnimation and I tried CreateVector4KeyframeAnimation:



Visual visual = ElementCompositionPreview.GetElementVisual(myUIElement);
var animation = visual.Compositor.CreateVector4KeyFrameAnimation();
Vector4 v4 = Vector4.Transform(new Vector4(), myMatrix4x4);
animation.InsertKeyFrame(1f, v4);
animation.Duration = TimeSpan.FromMilliseconds(3000);
visual.StartAnimation(nameof(visual.TransformMatrix), animation);


Which throws "The expression output does not match animating property type" as one might expect. I don't know what else to try. Do I have to create 16 separate scalar animations, one for each matrix value? That seems a bit crazy.



EDIT:
So I tried to just roll my own and use 16 scalar animations like so:



for (int i = 5; i <= 20; i++)

int row = (i / 4);
int column = (i % 4);
if (column == 0) column = 4;
var matrixAnimation = visual.Compositor.CreateScalarKeyFrameAnimation();
var matrixEasing = visual.Compositor.CreateLinearEasingFunction();
matrixAnimation.InsertExpressionKeyFrame(1f, "this.FinalValue", matrixEasing);
matrixAnimation.Target = nameof(visual.TransformMatrix) + ".M" + row + column;
matrixAnimation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds);
visual.ImplicitAnimations[nameof(visual.TransformMatrix) + ".M" + row + column] = matrixAnimation;



So the implicit animations are created and all seems great. Then to my dismay I write the code to change the read/write M11- M44 properties which ought to trigger the implicit animation and I get a compiler error:




"Cannot modify the return value of 'Visual.TransformMatrix' because it
is not a variable".




And assigning it a new Matrix4x4 does not trigger the implicit animation.







uwp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 15:46







Sean O'Neil

















asked Nov 13 '18 at 4:42









Sean O'NeilSean O'Neil

630414




630414







  • 1





    I've helped you report this issue to the relevant team. They're investigating it.

    – Xavier Xie - MSFT
    Nov 16 '18 at 9:46











  • Just to clarify I'm using keyframe implicit animations. I heaven't dug in and learned expression animations yet, but perhaps that's the only way to do it.

    – Sean O'Neil
    Nov 16 '18 at 13:31












  • 1





    I've helped you report this issue to the relevant team. They're investigating it.

    – Xavier Xie - MSFT
    Nov 16 '18 at 9:46











  • Just to clarify I'm using keyframe implicit animations. I heaven't dug in and learned expression animations yet, but perhaps that's the only way to do it.

    – Sean O'Neil
    Nov 16 '18 at 13:31







1




1





I've helped you report this issue to the relevant team. They're investigating it.

– Xavier Xie - MSFT
Nov 16 '18 at 9:46





I've helped you report this issue to the relevant team. They're investigating it.

– Xavier Xie - MSFT
Nov 16 '18 at 9:46













Just to clarify I'm using keyframe implicit animations. I heaven't dug in and learned expression animations yet, but perhaps that's the only way to do it.

– Sean O'Neil
Nov 16 '18 at 13:31





Just to clarify I'm using keyframe implicit animations. I heaven't dug in and learned expression animations yet, but perhaps that's the only way to do it.

– Sean O'Neil
Nov 16 '18 at 13:31












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273936%2fhow-to-animate-a-visual-transformmatrix%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273936%2fhow-to-animate-a-visual-transformmatrix%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3