■ FrameworkElement 클래스 : RequestBringIntoView 이벤트를 사용해 ScrollViewer 내부 객체 포커스시 자동 스크롤 방지하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainWindow.xaml

 

 

<Window x:Class="TestProject.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="800"

    Height="600"

    Title="FrameworkElement 클래스 : RequestBringIntoView 이벤트를 사용해 ScrollViewer 내부 객체 포커스시 자동 스크롤 방지하기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <ScrollViewer>

        <StackPanel Name="stackPanel">

            <Button Margin="10" Height="300" Background="Red"   Content="버튼 1" />

            <Button Margin="10" Height="300" Background="Green" Content="버튼 2" />

            <Button Margin="10" Height="300" Background="Blue" Content="버튼 3" />

        </StackPanel>

    </ScrollViewer>

</Window>

 

 

MainWindow.xaml.cs

 

 

using System.Windows;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

 

            this.stackPanel.AddHandler

            (

                FrameworkElement.RequestBringIntoViewEvent,

                new RequestBringIntoViewEventHandler(FrameworkElement_RequestBringIntoView)

            );

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 프레임워크 엘리먼트 뷰 표시 요청 처리하기 - FrameworkElement_RequestBringIntoView(sender, e)

 

        /// <summary>

        /// 프레임워크 엘리먼트 뷰 표시 요청 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void FrameworkElement_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)

        {

            e.Handled = true;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요