Silverlight 2.0 - 垂直滚动,水平换行

发布于 2024-07-09 18:25:41 字数 1357 浏览 7 评论 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 应该占据控件的主要区域, 如果高度不合适,则使用垂直滚动条。 当消息水平太长时应该换行。

滚动可以工作,但现在消息不会在右侧边缘换行。 他们就切断了。 它不限制宽度,只是隐藏 Horizo​​ntalScrollBar。 如果我设置 Horizo​​ntalScrollBarVisibility="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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独木成林 2024-07-16 18:25:41

尝试将 ScrollViewer 的 Horizo​​ntalScrollBarVisibility 设置为“禁用”(或者不指定值,因为“禁用”是默认值),然后 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文