在WPF TextBlock的自动垂直滚动条? [英] Automatic vertical scroll bar in WPF TextBlock?
问题描述
我在WPF中有一个的TextBlock
。我写了许多行了,这远超过其垂直高度。我希望这种情况发生时,垂直滚动条自动出现,但事实并非如此。我试图寻找在属性面板中滚动条属性,但没能找到。
I have a TextBlock
in WPF. I write many lines to it, far exceeding its vertical height. I expected a vertical scroll bar to appear automatically when that happens, but it didn't. I tried to look for a scroll bar property in the Properties pane, but could not find one.
我怎样才能使垂直滚动条对我的<$ C $自动创建C>的TextBlock 一旦它的内容超过其高度
How can I make vertical scroll bar created automatically for my TextBlock
once its contents exceed its height?
澄清:我宁愿从设计师做的,而不是通过直接写入到XAML
Clarification: I would rather do it from the designer and not by directly writing to the XAML.
推荐答案
包装在滚动查看器:
<ScrollViewer>
<TextBlock />
</ScrollViewer>
注意这个答案适用于的TextBlock
(只读文本元素)作为要求在原来的问题。
NOTE this answer applies to a TextBlock
(a read-only text element) as asked for in the original question.
如果你想显示滚动条在文本框
(可编辑的文本元素),然后使用的ScrollViewer
附加属性:
If you want to show scroll bars in a TextBox
(an editable text element) then use the ScrollViewer
attached properties:
<TextBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto" />
有关这两个属性的有效值为禁用
,自动
,隐藏
和可见
。
Valid values for these two properties are Disabled
, Auto
, Hidden
and Visible
.
这篇关于在WPF TextBlock的自动垂直滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!