Character-length of a text in a TextBlock
I have a TextBlock component in a WPF project. The content of the text is set from an RSS feed that is usually longer 开发者_开发问答that that can be displayed in the text box. How can I find out how many character may exist in my TextBlock component? I would also like to find out how much text is displayed to the user.
I tried to create my own TextTrimming-Method. I would have to know how much text is present in a label or a text block can be entered, so I can cut my string at the appropriate place.
Maybe everyone knows how the TextTrimming-Method works an can tell me!
Read the RSS feed into a string in code-behind file and then get the length
Why we developers, as a whole, feel the need to reinvent the wheel?
Why not simply try:
<Label MaxWidth="100">
<TextBlock TextTrimming="CharacterEllipsis">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
non orci tortor. Aenean commodo urna quis lacus convallis sit amet
tempor neque dictum. Nam aliquet pretium commodo. Nam tellus
velit, cursus a vulputate at, viverra sit amet mauris.
</TextBlock>
</Label>
精彩评论