Silverlight 2.0 - 垂直滚动,水平换行
在 silverlight 2.0 中。 我有一些内容想要垂直滚动并水平换行。 在控件中我有一个停靠面板。 DockPanel 的最后一个子级(填充它)是一个 ScrollViewer
<UserControl x:Class="MyProject.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WinControls="clr-namespace:Microsoft.Windows.Controls;
assembly=Microsoft.Windows.Controls"
Width="400" Height="300">
<WinControls:DockPanel LastChildFill="True">
...
<ScrollViewer x:Name="MessageScroll" HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Auto" BorderThickness="0" >
<Controls:TextDisplay x:Name="TextDisplay"></Controls:TextDisplay>
</ScrollViewer>
TextDisplay 控件 XAML 如下所示:
<UserControl x:Class="MyProject.TextDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock x:Name="TextDisplayText" TextWrapping="Wrap">
</TextBlock>
</UserControl>
我想要发生的情况: TextDisplay 应该占据控件的主要区域, 如果高度不合适,则使用垂直滚动条。 当消息水平太长时应该换行。
滚动可以工作,但现在消息不会在右侧边缘换行。 他们就切断了。 它不限制宽度,只是隐藏 HorizontalScrollBar。 如果我设置 HorizontalScrollBarVisibility="Auto" 我可以看到它们向右滚动。 我如何强制它包裹?
In silverlight 2.0. I have some content that i want to scroll vertically and wrap horizontally. In the controls I have a dock panel. The DockPanel's last child, which fills it, is a ScrollViewer
<UserControl x:Class="MyProject.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WinControls="clr-namespace:Microsoft.Windows.Controls;
assembly=Microsoft.Windows.Controls"
Width="400" Height="300">
<WinControls:DockPanel LastChildFill="True">
...
<ScrollViewer x:Name="MessageScroll" HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Auto" BorderThickness="0" >
<Controls:TextDisplay x:Name="TextDisplay"></Controls:TextDisplay>
</ScrollViewer>
The TextDisplay control XAML looks like this:
<UserControl x:Class="MyProject.TextDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock x:Name="TextDisplayText" TextWrapping="Wrap">
</TextBlock>
</UserControl>
What I want to happen: The TextDisplay should occupy the main area of the control,
with a vertical scrollbar if the height doesn't fit. The messages should wrap when they get too long horizontally.
The scrolling works, but now the messages don't wrap at the right-hand edge. they just cut off. It's not constraining the width, just hiding the HorizontalScrollBar. If I set HorizontalScrollBarVisibility="Auto" I can see them scrolling off to the right. How do i force it to wrap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 ScrollViewer 的 HorizontalScrollBarVisibility 设置为“禁用”(或者不指定值,因为“禁用”是默认值),然后 TextDisplay 将正确换行,并且不会显示水平滚动条。
Try setting the HorizontalScrollBarVisibility of the ScrollViewer to Disabled (or do not specify a value as Disabled is the default) then the TextDisplay will wrap correctly and the horizontal scroll bar will not be displayed.