Automatically Center TextBlocks
Now that I'm playing around alot with WPF/E I seem to have a lot of questions. :-)
Is there any nice/easy way to automatically center text in a TextBlock within a canvas (or even other objects)? With different font family's and sizes and no way to calculate the actual size of the rendered string on the client-side (Graphics.MeasureString works...but not unless a call is made to a Web Service or something that calculates a SizeF) it's difficult to know where to set the Canvas.Top and Canvas.Left positions for text blocks. Is there an easy way I'm missing maybe?
The problem today is there is no way to measure text (if you could do that, you could center it easily enough). I think Barak or Mike can explain better when the improved Text handling will make it in (pre or post v1). But as I've heard they want to improve it...just when is the question.
We are enabling the ability to get the rendered width and height of the TextBlock which you can use to manually center the text. Right now we don't have plans for a while to introduce a "center text" option though.
-mark
Program Manager
Microsoft
This post is provided "as-is"
An update to this now that we have the Feb CTP available -- you can use the ActualWidth to get the rendered width of the TextBlock enabling you to perform the calculation necessary for centering the text.
-mark
Program Manager
Microsoft
This post is provided "as-is"