1
votes

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

2

2 Answers

1
votes

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.

0
votes

Aaron McIver's answer points at the styles, and OP comments that their global style setting TextWrapping="WrapWithOverflow" was their problem. I had a similar problem but with a different solution. In my case the problem was that the style of ScrollViewer had just

<ScrollContentPresenter Margin="1" />

for the ScrollContentPresenter. The default template has

<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" Margin="{TemplateBinding Padding}" Grid.Row="0" />

Of the missing properties, the really important one is CanContentScroll.