开发者

String Length in Pixels

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 tha开发者_JS百科t 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.


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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜