Element scaling in C++
I'm having trouble figuring out how to apply scale to elements through code in c++.
I found this example in the Gallery sample
But it does nothing for me - the scale of the element doesn't change and if I call immediately after I set scale, it returns the old value.
Could you point me to the right way of doing this?
I found this example in the Gallery sample
Code: Select all
ScaleTransform* rootScale = (ScaleTransform*)mLayoutRoot->GetLayoutTransform();
rootScale->SetScaleX(scale);
rootScale->SetScaleY(scale);
Code: Select all
rootScale->GetScaleX()
Could you point me to the right way of doing this?
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Element scaling in C++
Hello,
LayoutTransform is used when you want that the new scaled element affects the layout of the container, so it modifies the Size returned by Measure and Arrange.
On the other hand, RenderTransform is not taken into account in the layout and only affects the rendering.
I think you want to use RenderTransform in this case. Also remember to set the correct transform object in your xaml or manually in code (otherwise you will get the default value, the Identity transform, a frozen resource that cannot be modified):
LayoutTransform is used when you want that the new scaled element affects the layout of the container, so it modifies the Size returned by Measure and Arrange.
On the other hand, RenderTransform is not taken into account in the layout and only affects the rendering.
I think you want to use RenderTransform in this case. Also remember to set the correct transform object in your xaml or manually in code (otherwise you will get the default value, the Identity transform, a frozen resource that cannot be modified):
Code: Select all
<Grid x:Name="LayoutRoot" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<ScaleTransform>
</Grid.RenderTransform>
...
</Grid>
Code: Select all
ScaleTransform* rootScale = (ScaleTransform*)mLayoutRoot->GetRenderTransform();
rootScale->SetScaleX(scale);
rootScale->SetScaleY(scale);
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Element scaling in C++
I forgot to answer this. Did you set a ScaleTrasnsform object in your mLayoutRoot object, or where you using the default value (the Identity transform).But it does nothing for me - the scale of the element doesn't change and if I call GetScaleX immediately after I set scale, it returns the old value.
Is it possible that before calling SetScaleX/Y you animated those values? Take into account that animated values have precendence over locally set values, so you need to clear animation before setting the new values in code:
Code: Select all
ScaleTransform* rootScale = (ScaleTransform*)mLayoutRoot->GetLayoutTransform();
rootScale->ClearAnimation(ScaleTransform::ScaleXProperty);
rootScale->SetScaleX(scale);
rootScale->ClearAnimation(ScaleTransform::ScaleYProperty);
rootScale->SetScaleY(scale);
Re: Element scaling in C++
Problem solved, thank you!
I missed that I had to add the ScaleTrasnsform object in the .xaml file.
New to this language, there's a lot to take in
Thank you for you help!
I missed that I had to add the ScaleTrasnsform object in the .xaml file.
New to this language, there's a lot to take in
Thank you for you help!
Re: Element scaling in C++
Great! Marking as solved
Who is online
Users browsing this forum: No registered users and 3 guests