开发者

String Length in Pixels

开发者 https://www.devze.com 2022-12-31 08:08 出处:网络
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

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

精彩评论

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