첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ EventTrigger 엘리먼트에서 CallMethodAction 객체를 사용해 이벤트 명령을 실행하는 방법을 보여준다.

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"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    Width="800"
    Height="600"
    Title="EventTrigger 엘리먼트 : CallMethodAction 객체를 사용해 이벤트 명령 실행하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Button
            Width="100"
            Height="30"
            Content="테스트">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseWheel">
                    <ei:CallMethodAction TargetObject="{Binding}" MethodName="button_MouseWheel" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;
using System.Windows.Input;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            DataContext = this;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 버튼 마우스 WHEEL 처리하기 - button_MouseWheel(sender, e)

        /// <summary>
        /// 버튼 마우스 WHEEL 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        public void button_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            MessageBox.Show($"마우스 휠을 움직였습니다 : {e.Delta}");
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,