Search code examples
wpftextboxscroll

wpf textbox cursor scrolling


What property do I need to set so that the text near the cursor within a WPF textbox is always visible. I have to set the width of a one line textbox and once I type outside of the width I can't see what I'm typing I can set ScrollViewer.CanContentScroll = True but that makes the height increase, which is better than the former but I would prefer the text near the cursor to be visible like common WinForms textbox behavior.

Any ideas? I figured a WPF guru or maybe even novice could answer this question faster than it would take me to experiment/google

Thanks in advance


Solution

  • The behavior you are describing should be how it operates by default. To test this I just created a TextBox...

    <TextBox Width="50" Height="22" ></TextBox>
    

    ...began typing and the most recent character I typed is where the cursor was living and therefore what was visible.

    Perhaps you have a style or something applied that is negating this default behavior.