我在一个TextBlock中有一个ScrollViewer,它与其窗口的拉伸对齐。我需要TextBlock表现如下:
scrollbars
TextBlock需要保持MinWidth的特定宽度以下调整大小,如果appear
TextWrapping或TextTrimming应工作于appropriately,则应使用滚动条
我如何获得这个功能?
我尝试过几种方法,包括绑定到ActualWidth & ActualHeight,但无法工作。
不会有那么难的,我错过了什么?
下面是要放入XamlPad的代码示例(尚未设置MinWidth ):
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock TextWrapping="Wrap" Text="Some really long text that should probably wordwrap when you resize the window." />
</ScrollViewer>
</Window>发布于 2009-12-30 19:56:16
这样做是可行的:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
Name="Scroller">
<TextBlock HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
MinWidth="100"
Width="{Binding ElementName=Scroller, Path=ViewportWidth}"
TextWrapping="Wrap"
Text="Some really long text that should probably wordwrap when you resize the window." />
</ScrollViewer>
</Window>发布于 2009-12-30 17:03:01
如果没有更多的细节,我所能做的就是提供标准的方法来做到这一点。基本上,将元素(其最小大小)托管在滚动查看器中;当滚动查看器调整到足够小的大小时,元素无法完全容纳其中,它将自动显示滚动条。示例:
<ScrollViewer>
<Button MinWidth="100" MinHeight="50"/>
</ScrollViewer>https://stackoverflow.com/questions/1981137
复制相似问题