Does anyone have any suggestions on how to justify read-only text (rendered into a TextBlock
) in Silverlight 2? WPF supports text justification by way of the TextAlignment
enumeration:
public enum TextAlignment
{
Left,
Right,
Center,
Justify // <--- Missing from Silverlight :(
}
However, Silverlight 2 only supports the following:
public enum TextAlignment
{
Center,
Left,
Right
}
Any ideas or suggestions gratefully received.
Off the top of my head, I can think of two not-so-easy ways to do this. One is rather lame; adding spaces between the words. The other would be to somehow parse the text so that each word is it's own text block, you could then use a Grid to left justify the first word of a line and right justify the last word of a line, then space the other blocks in the center cell using a stack panel or similar.
Determining which words are the start and end of a line would involve measuring the rendered size of each block and deciding if it will fit. It's not simple but it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With