Stop WPF ScrollViewer automatically scrolling to perceived content

前端 未结 2 604
后悔当初
后悔当初 2020-12-15 03:12

The Application

I am building an application which includes a range selector. This consists of two custom drawn Slider controls contain

相关标签:
2条回答
  • 2020-12-15 03:42

    By default when a control receives the logical focus, FrameworkElement calls its own BringIntoView method (from within its OnGotFocus method if it has keyboard focus). That results in a RequestBringIntoView event being generated that bubbles up the element tree to allow ancestor elements to bring that portion of the element into view. The ScrollViewer listens for this event and eventually will call MakeVisible on the associated IScrollInfo/ScrollContentPresenter which leaves it up to the panel to bring that portion into view (since the panel would know how it arranges its children). It then takes that returned rect it receives back and asks for that portion of itself to be brought into view (in case you had nested elements that would require some action to ensure the original element was brought into view). So one way to suppress this behavior would be to handle the RequestBringIntoView event on the sliders and mark the event handled.

    0 讨论(0)
  • 2020-12-15 03:56

    This may not work in this specific scenario, but a simple, clean solution to prevent a ScrollViewer from scrolling a focused element into view is to make the element unfocusable via Focusable=False. If an element cannot be focused then it will also not be automatically scrolled into view.

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