Search code examples
silverlightxamltextblockword-wraphyphenation

Soft hyphens in XAML?


does anybody have an idea whether it is possible to define "soft hyphens" or "soft linebreaks" in e.g. a TextBlock's text? Background: I would like to use TextWrapping="Wrap" on a TextBlock, but normally that won't do anything if the text contained in the TextBlock does not contain white space.

E.g.

<TextBlock TextWrapping="Wrap" Text="OneVeryLongWordThatDoesNotContainAnyWhiteSpaceAtAll" />

won't wrap if there is insufficient space. So I thought maybe there is a way to tell TextWrapping where the text may be wrapped.

I tried using the HTML &shy; (soft hyphen) entity, but this is not allowed in XAML apparently (won't compile).

Cheers, Alex


Solution

  • Alex,

    what do you mean by "won't wrap if there is insufficient space"? I tried your example code and it actually does wrap (it will break on every single character if necessary) when adding Width="100" or limiting by it's margins etc.

    Setting width to 100 i get the following result:

    OneVeryLongWor
    dThatDoesNotCon
    tainAnyWhiteSpa
    ceAtAll

    When you limit the height (like Height="20"), it won't actually break of course, but you can add TextTrimming="WordEllipsis" to get a result like this:

    OneVeryLongW...

    But oh well, it doesn't answer your question about Soft Hyphens, they obviously don't work.

    Best regards =)