-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Added VisualExtensions.Translation attached property #3956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added VisualExtensions.Translation attached property #3956
Conversation
|
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
|
@Sergio0694 these are effectively wrappers like I called out in this WinUI issue, eh? microsoft/microsoft-ui-xaml#2130 I don't think I realized we had these in the Toolkit already... 🤦♂️ This is basically just adding one of the ones we missed? Did we get the whole list from the WinUI issue? |
|
@Sergio0694 do we have all the cases covered now? Is there UWP documentation we can improve on this, or should we call these cases out somehow more explicitly in our own docs? |
The unit tests I've added for this extension should cover the expected use case scenario, yes 🤔
I think these details should be covered in the docs for UWP itself, since these are all standard APIs from there. |
|
Thanks @Sergio0694, yeah, if you could at least find the most relevant existing docs and check if there are any issues or create a new one to call out these important details that'd be a good starting point then. At least we'll have good helpers and behavior in the Toolkit now on top of it. Was there any other properties we're missing exposed on the VisualExtensions beyond this one? |
|
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
|
Also, did you want to add your test image code you did above as a sample in the Sample App? 😉 |
Correction, this is not the case.
All these translations can be stacked together and set/animated indipendently. I'm not entirely sure why that is the case, and in particular why And to answer your question and clarify, the extension in this PR works on
Sure, I can put together a small sample page to showcase the extension 🙂 EDIT: done in ca7baea, added the samples to the "VisualExtensions" page. |
|
Thanks for the detailed details @Sergio0694! Please open an issue on the WinUI repo about this confusion with your details here (feel free to point to this PR too), if you send the link I can add our wct label on it. They'll at least know where to reach out to get docs updated, they'd probably have to be contacted anyway to help clarify/update the content anyway for remarks. |
|
@RosarioPulella @Kyaa-dost want to test out the sample on Monday? Then @Sergio0694 can just link to the newly opened WinUI issue for this, and I think we'll be good to go! |
e81983e to
129ab97
Compare
Kyaa-dost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice Work @Sergio0694! Looks great 🚀
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The
VisualExtensionsclass lacks an attached property to set the"Translation"property of a UI element.What is the new behavior?
This PR adds a
VisualExtensions.Translationattached property.The behavior and implementation mirrors that of the other extensions.
Here's a GIF that shows both XAML hot-reload and this extension being combined with the animation system 🚀 🚀 🚀
Additional info
This extension now works just fine, and can be combined with the existing animation APIs to start a translation animation with an implicit starting point just fine. The reason why it wasn't originally working was because I incorrectly assumed that the "Translation" property in question was
Visual.TransformMatrix.Translation, but turns out that wasn't the case 😄When setting
ElementCompositionPreview.SetIsTranslationEnabled, the Composition layer adds a new "Translation" property toCompositionObject.Properties(Visualis aCompositionObjecttoo), and that's the property that is actually being animated in this case. In fact, you can set/animate both this property andVisual.TransformMatrixat the same time, and the final translation position for the object will just be the combination of the transform matrix + the additional explicit translation from this "hidden" property. That also explains why the animation didn't seem to work before: in fact it was working, but it was animating a different target ("Translation" instead ofTransformMatrix.Translation) which was already at0(as it had never been set before), so it seemed as though the animation was just not doing anything. This also explains the final value for that transform matrix being unchanged 🙂Marking this PR as ready for review, as this functionality is now working correctly! 🎉
Original (outdated) notes (click to expand):
This attached property comes with a caveat, which is that if it's used to set thee
"Translation"property of aVisualbefore an animation, and then the animation is started without an initial value, the animation will just not run. In fact, the"Translation"property won't even be changed at all to the final value of the animation once it completes (though it still takes the expected duration for the animation to complete, it just... Does nothing). This only happens for"Translation", whereas doing exactly the same with eg.Visual.Offsetworks just fine. For instance, consider this repro code:Running this and clicking on the button will have the button remain in the same initial position, and those
beforeandaftervalues will still be exactly the same (so160,80,0in this case). If you try to change the target property toOffsetin both XAML and C# instead, the animation will run as expected, and theaftervalue will in fact change to0.This seems an issue with the framework, or at the very least a very specific behavior for
"Translation"that's not consistent with the otherVisualproperties, and that I don't see documented on the MS docs for eitherVisual.TransformMatrixorElementCompositionPreview.SetIsTranslationEnabled. I might open an issue in the WinUI repo about this, at least to try to get more information on this, but opening this PR in the meantime to gather feedbacks and because the actualVisualExtensions.Translationproperty itself does work, so we might also just want to merge it in the meantime 🙂PR Checklist
Please check if your PR fulfills the following requirements:
Pull Request has been submitted to the documentation repository instructions. Link:Sample in sample app has been added / updated (for bug fixes / features)Icon has been created (if new sample) following the Thumbnail Style Guide and templates