I have a TextBox that does a SelectAll() when it gets focus. Works great. The problem is that if the contents don't fit in the box, then the SelectAll results in the contents getting scrolled to the end. I want it to scroll to the front instead - this box is being used with number fields.
My question is: is it possible to SelectAll() but avoid the scrolling?
The workaround I have right now is to queue up a ScrollToHome. I'm not liking this too much because it sometimes causes a pop as the text renders in one position then another.
public new void SelectAll()
{
base.SelectAll();
// changing selection does something with a queued scroll request, so have to queue ours in the back. this still may cause a flash
// if a render slips through. would like to find a better way to do this.
Dispatcher.BeginInvoke(DispatcherPriority.Background, ScrollToHome);
}
Note that the ScrollToHome has to be queued like this or it gets "overwritten" due to some other queued event..I'm guessing a notify-changed event internal to the textbox system. I poked around in the source and it's pretty complicated, had trouble figuring out exactly where it is doing its request to scroll.
So what I'm looking for is one of the following:
- How to SelectAll() without any scrolling occurring or with it scrolling to the front.
- How to force an update to the display so that I don't get the popping.