Silverlight text trimming and wrapping issue

℡╲_俬逩灬. 提交于 2019-12-24 00:49:30

问题


I have the following layout in XAML:

    <StackPanel Height="40">
        <TextBlock TextWrapping="Wrap" TextTrimming="WordEllipsis"  Margin="0,10,0,10"
                               LineHeight="18" FontSize="12">
                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce dapibus commodo dui vulputate laoreet. Donec metus purus, consectetur ut sagittis ut, vestibulum id diam. Suspendisse in urna sem. Ut purus arcu, placerat quis tempus cursus, elementum sed sem. Duis condimentum semper tortor, a pulvinar dolor semper sit amet.
        </TextBlock>
    </StackPanel>

So inside my stackpanel there is a textbox. In this example I set the height in the parent stackpanel, but in my real application it is set some level higher.

I have to display the text in multiline and use ellipsis as trimming behavior. The problem is if I use the XAML code above, the last line of the text gets cut. I've attached a screenshot to illustrate the behavior:

Is there a way to solve this issue? The expected behavior would be to show only the first line and the ellipsis at the end of it.


回答1:


Well, the issue caused because of I used StackPanels. The content's height, inside the StackPanel was as big as it should be to display all content in it. However, the parent StackPanel have a height limit, and the content inside got clipped.

I've replaced my StackPanel to a Grid and trimming & wrapping works like a charm now.




回答2:


from MSDN (http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.texttrimming%28v=vs.95%29.aspx)

The TextTrimming property has no effect unless the TextWrapping property is set to NoWrap.



来源:https://stackoverflow.com/questions/8242732/silverlight-text-trimming-and-wrapping-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!