views:

75

answers:

2

How can I obtain the lenght of a string (given a font , size weight etc) in Pixels? I have seen recomendations to try System.Drawing.Graphics.* but that Assembly / Namespace doesn't seem to be available to me in silverlight.

I hope to center a text box under an image, but the text is provided dynamically.

A: 

Thought I not familiar with developing for Silverlight, I think that this might be of use to you.

krs1
Thx - but no access to System.Graphics.Drawing to get the GraphicsUnit class...
akaphenom
Using WPF doesn't mean System.Drawing is unavailable. You can still manually add a reference to it. (Edit: Oh wait, Silverlight, I forgot! Maybe you can't.)
YotaXP
+3  A: 

Since your goal is to Centre the TextBox don't mess around with calculating width etc. Just tell the Container to centre the textbox.

eg.

<Grid>
    <Image Source="ToolBox Avatar.png" Stretch="Fill"/>
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="TextBlock" TextWrapping="Wrap"/>
</Grid>
Graeme Bradbury
It is a good solution - but my items are on different "rows" I should probably go back and redesign UI.
akaphenom