在 RenderTransfrom 属性上应用 ScaleTransfrom 后,新尺寸仍然相同
在渲染的变换属性上进行缩放变换后,我得到了相同的尺寸。这是代码:
shape.Width = 100; shape.Height=100;
shape.RenderTransform = new ScaleTransform(.5, .5);
textBox.text = shape.ActualWidth + " " + shape.ActualHeight;
我尝试获取渲染的几何边界的宽度和高度,但仍然相同。我也尝试了LayoutTransfrom
,仍然不起作用。我做错了什么,任何帮助将不胜感激。
I get the same dimensions after I do a scale transfrom on the rendered transfrom property. Here is the code:
shape.Width = 100; shape.Height=100;
shape.RenderTransform = new ScaleTransform(.5, .5);
textBox.text = shape.ActualWidth + " " + shape.ActualHeight;
I've tried getting the rendered geometry bounds' width and height, and still the same. I also tried LayoutTransfrom
, still didn't work. What am I doing wrong, any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试设置 LayoutTransform 而不是 RenderTransform。
Try setting LayoutTransform instead of RenderTransform.
LayoutTransform 和 RenderTransform 之间的主要区别在于应用变换的时间。使用渲染变换时,在布局过程中会使用对象的完整大小,并且只有在完成之后才会变换对象。其他元素不受此影响。使用 LayoutTransform,对象已在布局阶段进行转换,这意味着对于所有预期目的,对象的边界框都会发生变化。所有其他元素也适应这种变化。
两者都不会更改 ActualWidth 或 ActualHeight,因为这会影响正在转换的对象的内部布局,从而使转换操作变得无用。
您可以在我为您准备的以下示例中看到这一点:
当您按下按钮时,会附加以下操作:
OuterBorder1 具有对齐方式的覆盖,以确保它紧密贴合项目。
正如您所看到的,使用 RenderTransform 时,尺寸不会改变。使用 LayoutTransform,变换后的元素的宽度保持不变,但它周围的容器会受到影响。
The main difference between LayoutTransform and RenderTransform is when the transform is applied. When using Render Transform the full size of the object is used during the layout process, and only after that has finished the object is transformed. Other elements are ot influenced by this. With LayoutTransform the object is transformed during the layout phase already, which means that for all intended purposes the bounding box of the object changes. All other elements adapt to this change as well.
Neither will change ActualWidth or ActualHeight, as this would influence the inner layout of the object that's being transformed rendereing the transform operation useless.
You can see this in the following example I whipped up for you:
When you press the buttons, the following actions are attached:
The OuterBorder1 has an override on alignment to make sure it fits tight around the item.
As you can see, with RenderTransform neither size changes. With LayoutTransform the transformed element's width remains the same, but the container surrounding it is influenced.
尝试等待转换完成,我们知道它的方法是使用快速的 1 毫秒
DoubleAnimation
及其Completed
事件。在此事件处理程序中检查新尺寸。代码背后...
Try and wait till the tranform finishes, the way we can know it is by using a fast 1 miilisecond
DoubleAnimation
and itsCompleted
event. In this event handler check for new dimesions.Code behind ...