为了使TextBlock能自动换行,并且在指定了高度的情况下必要时候出现纵向滚动条,我把TextBlock包在了ScrollViewer中,为了使用ScrollViewer只显示纵向滚动条,我把ScrollViewer的HorizontalScrollBarVisibility属性设置为"Hidden”,但是设置TextBlock.TextWrapping属性为"Wrap"后发现还是没有换行,仔细想想是因为虽然你要求TextBlock可以换行,但是控件的宽度被里面的文字撑大了,所以在TextBlock看来是不需要换行的。经过一翻检查,抱着试试看的心态将ScrollViewer.HorizontalScrollBarVisibility属性设置为"Disabled",结果效果达到了。
<
ScrollViewer
ScrollViewer.VerticalScrollBarVisibility
="Auto"
HorizontalScrollBarVisibility
="Disabled"
Style
="
{StaticResource PageWrapperScrollViewerStyle}
"
>
< TextBlock Text =" {Binding Description} " Foreground =" {TemplateBinding Foreground} " TextWrapping ="Wrap" />
</ ScrollViewer >
< TextBlock Text =" {Binding Description} " Foreground =" {TemplateBinding Foreground} " TextWrapping ="Wrap" />
</ ScrollViewer >
效果图: