jon*_*ers 19 .net c# wpf textblock scrollviewer
我有一个TextBlock内部的ScrollViewer,与拉伸到其窗口对准.我需要TextBlock表现如下:
TextBlock保持a MinWidth和滚动条的需要TextWrapping或者TextTrimming应该适当地工作我该如何获得此功能?
我尝试了几种方法,包括绑定到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>
Run Code Online (Sandbox Code Playgroud)
jon*_*ers 26
这有效:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18813 次 |
| 最近记录: |