[C#/WPF] EventManager 클래스 : RegisterClassHandler 정적 메소드를 사용해 특정 라우팅 이벤트에 대한 클래스 처리기 등록하기
C#/WPF 2022. 1. 27. 23:28728x90
반응형
728x170
▶ 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="EventManager 클래스 : RegisterClassHandler 정적 메소드를 사용해 특정 라우팅 이벤트에 대한 클래스 처리기 등록하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button Name="runButton"
Width="100"
Height="30"
Content="실행" />
<Button Name="waitButton"
Margin="0 10 0 0"
Width="100"
Height="30"
Content="대기" />
</StackPanel>
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using System.Windows;
using System.Windows.Controls;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
EventManager.RegisterClassHandler
(
typeof(Button),
MouseLeftButtonDownEvent,
new RoutedEventHandler(button_MouseLeftButtonDown)
);
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 버튼 마우스 왼쪽 버튼 DOWN 처리하기 - button_MouseLeftButtonDown(sender, e)
/// <summary>
/// 버튼 마우스 왼쪽 버튼 DOWN 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void button_MouseLeftButtonDown(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
if(button.Name == "runButton")
{
MessageBox.Show(this, "실행 버튼 위에서 마우스 왼쪽 버튼을 눌렀습니다.");
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 투명 윈도우 마우스 따라다니기 (0) | 2022.01.29 |
---|---|
[C#/WPF] Visual 클래스 : PointToScreen 메소드를 사용해 마우스 화면 좌표 구하기 (0) | 2022.01.29 |
[C#/WPF] Button 엘리먼트 : FocusVisualStyle 속성을 사용해 포커스 비주얼 스타일 설정하기 (0) | 2022.01.28 |
[C#/WPF] UIElement 클래스 : GotFocus/LostFocus 이벤트를 사용해 키보드 포커스 획득/상실시 처리하기 (0) | 2022.01.28 |
[C#/WPF] WeakEventManager<TEventSource, TEventArgs> 클래스 : AddHandler 정적 메소드를 사용해 이벤트 핸들러 추가하기 (0) | 2022.01.28 |
[C#/WPF] ControlTemplate 엘리먼트 : Button 엘리먼트 정의하기 (0) | 2022.01.27 |
[C#/WPF] Decorator 엘리먼트 : 커스텀 버튼 크롬 만들기 (0) | 2022.01.27 |
[C#/WPF] ButtonChrome 엘리먼트 사용하기 (0) | 2022.01.27 |
[C#/WPF] 커스텀 포커스 범위 사용하기 (0) | 2022.01.27 |
[C#/WPF] Image 클래스 : 이미지 색상 선택기 사용하기 (0) | 2022.01.22 |
댓글을 달아 주세요