Automatic vertical scroll bar in WPF TextBlock?

后端 未结 10 1919
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 07:25

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 happe

相关标签:
10条回答
  • 2020-12-07 08:14
    <ScrollViewer Height="239" VerticalScrollBarVisibility="Auto">
        <TextBox AcceptsReturn="True" TextWrapping="Wrap" LineHeight="10" />
    </ScrollViewer>
    

    This is way to use the scrolling TextBox in XAML and use it as a text area.

    0 讨论(0)
  • 2020-12-07 08:22

    I tried to to get these suggestions to work for a textblock, but couldn't get it to work. I even tried to get it to work from the designer. (Look in Layout and expand the list by clicking the down-arrow "V" at the bottom) I tried setting the scrollviewer to Visible and then Auto, but it still wouldn't work.

    I eventually gave up and changed the TextBlock to a TextBox with the Readonly attribute set, and it worked like a charm.

    0 讨论(0)
  • 2020-12-07 08:25

    can use the following now:

    <TextBox Name="myTextBox" 
             ScrollViewer.HorizontalScrollBarVisibility="Auto"
             ScrollViewer.VerticalScrollBarVisibility="Auto"
             ScrollViewer.CanContentScroll="True">SOME TEXT
    </TextBox>
    
    0 讨论(0)
  • 2020-12-07 08:27

    You can use

    ScrollViewer.HorizontalScrollBarVisibility="Visible"
    ScrollViewer.VerticalScrollBarVisibility="Visible"
    

    These are attached property of wpf. For more information

    http://wpfbugs.blogspot.in/2014/02/wpf-layout-controls-scrollviewer.html

    0 讨论(0)
提交回复
热议问题