- RequestBringIntoView


ScrollViewer 에는 내부의 객체에 Focus가 되었을 때, 자동으로 해당 객체를 향해 스크롤되도록 하는 기능이 있다. 

이 기능을 확인하기 위해 다음과 같은 구조를 만들어 보자.


<ScrollViewer>

     <StackPanel>

        <Button Height="200" Margin="10" Background="Red">Button 1</Button>

        <Button Height="200" Margin="10" Background="Blue">Button 2</Button>

        <Button Height="200" Margin="10" Background="Green">Button 3</Button>

    </StackPanel>

</ScrollViewer>



실행을 하고, Button2를 눌러보자. 그러면 스크롤뷰어가 Button2를 향해 움직이는 것을 확인할 수 있다.




이 기능을 막는 방법은 다음과 같다.

해당 ScrollViewer 내부의 객체, Focus 될 객체에서 RequestBringIntoView 라는 이벤트를 잡아 e.Handled=true 로 처리해주면 된다.


위의 예제에서는 다음과 같이 처리하면 된다.


xaml :

<Button Height="200" Margin="10" Background="Blue"

                        RequestBringIntoView="Button_RequestBringIntoView">Button 2</Button>


c# :

private void Button_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)

{

        e.Handled = true;

}





+ Recent posts