Sean
Sean

Reputation: 346

How do I calculate the rendered location of the corners of a textblock?

I am trying to get the rendered location of the corners of a textblock. I can't seem to find out how to do it. The textblock is bound by a border, which in turn in bound by a grid. Therefore the textblock and the border have no dimensions that I can pull in relation to the rest of the Window. I tried the following code, but only part of it works. The margin is 0 and the ActualWidth is 13.2. By the time that this line has been reached, the window and textblocks have been rendered.

double rightBound = textBlock.Margin.Left + textBlock.ActualWidth;

Update: I have the following code which mostly does what I want. However, the points DO NOT line up with the UI elements well; they appear to be arbitrarily placed near the elements. The points do not line up with the boundaries of the block.

Point blockPoint = textBlock.TranslatePoint(new Point(0, 0), myMainWindow);

Upvotes: 1

Views: 148

Answers (1)

Ben
Ben

Reputation: 153

So your text box isn't dimensioned and is encapsulated by a border... The code you gave above might be grabbing the position of the text within the border, thus appearing like the lines are drawn randomly inside the element. Try grabbing the encapsulating border's position.

Upvotes: 1

Related Questions