How to ensure correct positioning of TextBlock Text within a Rectangle?

It does not seem that the TextBlock in WPF/E (as opposed to WPF that have properties for Text alignment) have properties/methods for alignment of text. I have a rectangle (with a certain width and height) in which I want to position some text - using TextBlock - in the center; this has to be done programmatically on the server side when generating the XAML stream. Example,

<CanvasHeight="750"Width="750"xmlns="http://schemas.microsoft.com/client/2007"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Background="transparent">

<RectangleHeight="100"Width="150"Canvas.Left="300"Canvas.Top="325"Stroke="Navy"StrokeThickness="1"Fill="Silver"/>
<
TextBlockFontSize="16"FontFamily="Georgia"FontWeight="Bold"Canvas.Top="365"Canvas.Left="320">Topic</TextBlock>

</Canvas>

Any ideas of how to do this - any response will be highly appreciated, Thanks?

Kind Regards
Hans P. Dramstad

[4830 byte] By [HPD] at [2007-12-31]
# 1

Hans

Yes I have this problem to, I am looking at finding the ActualWidth and ActualHeight of the text and then adjusting it accordingly.

There is a reference here

http://msdn2.microsoft.com/en-us/library/system.windows.frameworkelement.actualwidth.aspx

http://msdn2.microsoft.com/en-us/library/system.windows.frameworkelement.actualheight.aspx

hope this helps

Richard

rgny at 2007-9-7 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...