滚动文本块

发布于 2024-09-07 13:40:13 字数 694 浏览 7 评论 0原文

我在同一位置有一个 TextBlock 和一个 Textbox。根据用户所处的模式,我使一个可见,另一个折叠。这工作正常,但是如何使 Textblock 可滚动?我想我应该使用 ScrollViewer,但我不知道为什么它不起作用。我尝试过调整高度(自动和固定),但它不会滚动。我的xaml是这样的:

<ScrollViewer x:Name="detailsScroller" Height="285" Width="480"  Canvas.Top="76" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Canvas x:Name="infoCanvas" Width="478"  >
     <TextBlock x:Name="textblockInfo" TextWrapping="Wrap"  Width="462" Height="197"  Canvas.Left="8"/>
     <TextBox x:Name="textboxInfo" TextWrapping="Wrap"  Width="478" AcceptsReturn="True" Height="300" Visibility="Collapsed" />
    </Canvas>
</ScrollViewer>

谢谢!

I have a TextBlock and a Textbox in the same location. Depending on what mode the user is in, I make one visible and the other collapsed. This is working fine, but how can I make the Textblock scrollable? I figured I should use a ScrollViewer, but I don't know why it's not working. I've tried messing around with the height (auto and fixed), but it won't scroll. My xaml is this:

<ScrollViewer x:Name="detailsScroller" Height="285" Width="480"  Canvas.Top="76" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Canvas x:Name="infoCanvas" Width="478"  >
     <TextBlock x:Name="textblockInfo" TextWrapping="Wrap"  Width="462" Height="197"  Canvas.Left="8"/>
     <TextBox x:Name="textboxInfo" TextWrapping="Wrap"  Width="478" AcceptsReturn="True" Height="300" Visibility="Collapsed" />
    </Canvas>
</ScrollViewer>

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

情丝乱 2024-09-14 13:40:13

不要在文本框中输入高度
这对我来说非常有效:

    <ScrollViewer Height="192" HorizontalAlignment="Left" Margin="12,34,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="404">
        <TextBlock VerticalAlignment="Top"  Name="textBlock1" Text="TextBlock" Width="378" TextWrapping="Wrap" />
    </ScrollViewer> 

Don't put a height in the textbox.
This worked perfectly for me:

    <ScrollViewer Height="192" HorizontalAlignment="Left" Margin="12,34,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="404">
        <TextBlock VerticalAlignment="Top"  Name="textBlock1" Text="TextBlock" Width="378" TextWrapping="Wrap" />
    </ScrollViewer> 
难理解 2024-09-14 13:40:13

您可能想参考讨论 和 MSFT 确认文本控件滚动在当前 CTP 中仍在进行中。 Beta 版本应该不会太远,希望届时能有更多相关内容。

You might like to refer to the discussion and MSFT confirmation that text control scrolling is still a work in progress as at the current CTP. Beta shouldnt be too far away, hopefully more on this then.

层林尽染 2024-09-14 13:40:13

下面的代码有效:由于您的子控件(即文本块)的高度和宽度不等于滚动查看器的宽度和高度,因此滚动条不显示。我刚刚为滚动查看器中定义的控件提供了与滚动查看器相同的高度和宽度,它可以工作。

<ScrollViewer x:Name="detailsScroller" Height="285" Width="480"  Canvas.Top="76" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Canvas x:Name="infoCanvas" Height="285" Width="480"  >
     <TextBlock x:Name="textblockInfo" TextWrapping="Wrap"  Height="285" Width="480" Canvas.Left="8"/>
     <TextBox x:Name="textboxInfo" TextWrapping="Wrap"  Width="478" AcceptsReturn="True" Height="300" Visibility="Collapsed" />
    </Canvas>
</ScrollViewer>

The below code works : As your child control(ie., textblock) has a height and width that is not equal to the width and height of your scroll viewer and hence the scroll bars don't display. I have just given same height and width as the scroll viewer for the controls defined inside it it works.

<ScrollViewer x:Name="detailsScroller" Height="285" Width="480"  Canvas.Top="76" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Canvas x:Name="infoCanvas" Height="285" Width="480"  >
     <TextBlock x:Name="textblockInfo" TextWrapping="Wrap"  Height="285" Width="480" Canvas.Left="8"/>
     <TextBox x:Name="textboxInfo" TextWrapping="Wrap"  Width="478" AcceptsReturn="True" Height="300" Visibility="Collapsed" />
    </Canvas>
</ScrollViewer>
情域 2024-09-14 13:40:13

如果您希望内容滚动,请确保滚动条可见。

<TextBox Text="{Binding SomethingReallyLong}" 
 TextWrapping="Wrap" 
 VerticalScrollBarVisibility="Visible"/>        

If you want the contents to scroll, make sure a scrollbar is visible.

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