滚动文本块
我在同一位置有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要在文本框中输入高度。
这对我来说非常有效:
Don't put a height in the textbox.
This worked perfectly for me:
您可能想参考讨论 和 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.
下面的代码有效:由于您的子控件(即文本块)的高度和宽度不等于滚动查看器的宽度和高度,因此滚动条不显示。我刚刚为滚动查看器中定义的控件提供了与滚动查看器相同的高度和宽度,它可以工作。
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.
如果您希望内容滚动,请确保滚动条可见。
If you want the contents to scroll, make sure a scrollbar is visible.