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

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 the screen.

I want to get the size of the TextBox as it is currently on the screen. If I get DesiredSize or ActualSize or even RenderedSize I always get 100.

Any suggestions?

Update: I could probably get the ActualWidth of the ViewBox and divide it by the ActualWidth of it's child which would give me the current scale factor and expose that as a property somehow but I'm not sure that's the best way to do it.

Answers


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))

Need Your Help

How to plot graph with numbers (strings in between)?

matlab graph plot octave

I want to plot a graph with 2 arrays, One is for time (X-Axis) and the other is for current (Y-Axis) but my scenario has some events like: interrupt received, timer expired or component up.

Making new relic work on a grails app in heroku

maven grails heroku newrelic javaagents

I'm having real trouble making new relic work on my grails app in Heroku, This are the things I've tried without success:

Last-Value Property in HornetQ 2.1.2.Final

jboss jms jmx hornetq

How does the Last-Value Property work in HornetQ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.