Dreamine.MVVM.Behaviors.Wpf 1.0.5
Dreamine.MVVM.Behaviors.Wpf 산업 자동화 및 I/O 기능을 제공합니다.
로딩중...
검색중...
일치하는것 없음
WindowDragBehavior.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.MVVM.Behaviors.Core.Base;
2using System.Windows.Input;
3using System.Windows;
4
6{
15 public class WindowDragBehavior : Behavior<FrameworkElement>
16 {
25 protected override void OnAttached()
26 {
27 base.OnAttached(); // 기본 동작 실행
28 // AssociatedObject (이 경우 FrameworkElement)에 MouseLeftButtonDown 이벤트를 추가합니다.
29 AssociatedObject!.MouseLeftButtonDown += OnMouseLeftButtonDown;
30 }
31
40 protected override void OnDetaching()
41 {
42 base.OnDetaching(); // 기본 동작 실행
43 // AssociatedObject에서 MouseLeftButtonDown 이벤트를 제거합니다.
44 AssociatedObject!.MouseLeftButtonDown -= OnMouseLeftButtonDown;
45 }
46
71 private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
72 {
73 // 왼쪽 버튼이 눌린 상태에서만 창 드래그를 수행합니다.
74 if (e.ButtonState != MouseButtonState.Pressed)
75 {
76 return;
77 }
78
79 // 현재 Behavior가 연결된 요소가 포함된 Window를 찾습니다.
80 Window window = Window.GetWindow(AssociatedObject);
81
82 // Window가 존재하면 DragMove를 호출하여 창 이동을 시작합니다.
83 window?.DragMove();
84 }
85 }
86}
void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)