Get the size (after it has been “stretched”) of an item in a ViewBox

核能气质少年 提交于 2019-11-30 12:41:30
Markus Hütter

This is how you get the ScaleTransform the ViewBox exerts on its children:

var child = VisualTreeHelper.GetChild(viewBox, 0) as ContainerVisual;
var scale = child.Transform as ScaleTransform;

Here viewBox is the ViewBox that textbox sits in. Then you can just multiply scale.ScaleX * textBox.ActualWidth and you get the size in Screen coordinates

But it gets even easier! To get that textbox's size directly in Screen Coordinates you do:

textbox.PointToScreen(new Point(textbox.ActualWidth,textbox.ActualHeight)) - textbox.PointToScreen(new Point(0,0))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!