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

前端 未结 1 1229
后悔当初
后悔当初 2020-12-16 18:04

Consider the following:

Let\'s say the Window is 1024x768 and the ViewBox fills the entire window, this means the TextBox is really large on th

相关标签:
1条回答
  • 2020-12-16 18:34

    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))
    
    0 讨论(0)
提交回复
热议问题