Dreamine.MVVM.Behaviors.Wpf
Dreamine MVVM Behavior 시스템의 WPF 구현 레이어입니다.
이 패키지는 다음 라이브러리를 기반으로 동작합니다.
Dreamine.MVVM.Behaviors.Core
WPF UI 요소에 Behavior를 부착하여 MVVM 구조를 유지하면서 사용자 인터랙션 로직을 확장할 수 있도록 합니다.
목적
MVVM 구조에서 UI 이벤트 처리 로직을 코드비하인드에 작성하는 것은 구조적인 결합도를 높입니다.
Behavior 패턴을 사용하면 XAML에서 선언적으로 UI 동작을 확장할 수 있습니다.
Dreamine.MVVM.Behaviors.Wpf 는 다음 기능을 제공합니다.
- XAML 기반 Behavior 연결
- 여러 Behavior 조합 지원
- MVVM 친화적인 UI 확장 구조
아키텍처
Dreamine Behavior 구조
Dreamine.MVVM.Behaviors.Core ↓ Dreamine.MVVM.Behaviors.Wpf ↓ Application Behaviors
Core는 Behavior 기반 구조를 제공하고
Wpf 패키지는 실제 WPF 런타임 연결을 담당합니다.
구성 요소
BehaviorCollection
하나의 UI 요소에 여러 Behavior를 연결할 수 있도록 하는 컬렉션 컨테이너입니다.
예시
<Button>
<i:Interaction.Behaviors>
<behaviors:WindowDragBehavior/>
</i:Interaction.Behaviors>
</Button>
역할
- Behavior 저장
- Attach / Detach 라이프사이클 관리
- AssociatedObject 전달
Interaction
XAML에서 Behavior를 연결하기 위한 static 헬퍼 클래스입니다.
다음 Attached Property를 제공합니다.
Interaction.Behaviors
이 속성을 통해 BehaviorCollection을 DependencyObject에 연결합니다.
Interaction.GetBehaviors(...) 호출은 빈 컬렉션만 생성하며, WindowDragBehavior 같은 동작은 XAML에서 명시적으로 선언해야 합니다.
WindowDragBehavior
이 패키지에 포함된 예제 Behavior입니다.
마우스로 WPF Window를 드래그하여 이동할 수 있도록 합니다.
대표 사용 예
Borderless Window
예시
<Grid>
<i:Interaction.Behaviors>
<behaviors:WindowDragBehavior/>
</i:Interaction.Behaviors>
</Grid>
설치
NuGet 패키지 설치
dotnet add package Dreamine.MVVM.Behaviors.Wpf
또는 프로젝트 참조 방식 사용
패키지 관계
Dreamine.MVVM.Behaviors.Core
Behavior 기본 인프라 제공
Dreamine.MVVM.Behaviors
공통 Behavior 구현
Dreamine.MVVM.Interactions
Event Trigger / Interaction 확장
License
MIT License
구조 다이어그램
classDiagram
class WpfBehaviorBase~T~ {
<<abstract>>
+AssociatedObject T
#OnAttached() void
#OnDetaching() void
}
class FocusBehavior {
+bool FocusOnLoad
+bool SelectAllOnFocus
#OnAttached() void
}
class ScrollIntoViewBehavior {
+object SelectedItem
#OnAttached() void
-ScrollToSelected() void
}
class DragDropBehavior {
+IRelayCommand DropCommand
+string AllowedExtensions
#OnAttached() void
-OnDrop(object, DragEventArgs) void
}
class WindowBehavior {
+bool HideOnClose
+IRelayCommand ClosingCommand
#OnAttached() void
}
class TextBoxWatermarkBehavior {
+string Watermark
+Brush WatermarkBrush
#OnAttached() void
}
WpfBehaviorBase~T~ <|-- FocusBehavior
WpfBehaviorBase~T~ <|-- ScrollIntoViewBehavior
WpfBehaviorBase~T~ <|-- DragDropBehavior
WpfBehaviorBase~T~ <|-- WindowBehavior
WpfBehaviorBase~T~ <|-- TextBoxWatermarkBehaviorAPI 문서
타입
\if KO 📦 Dreamine용 Behavior 컬렉션입니다. - XAML에서 여러 개의 Behavior 요소를 포함할 수 있는 컬렉션 컨테이너입니다. \endif \if EN Encapsulates behavior collection functionality and related state. \endif
\if KO Interaction 기능과 관련 상태를 캡슐화합니다. \endif \if EN Provides attached properties for declaring WPF behavior collections. \endif
\if KO 📌 WPF Window를 마우스로 드래그하여 이동 가능하게 만드는 Behavior입니다. Dreamine에서는 View의 시각적 행동을 확장하는 유틸성 모듈로 이 클래스를 구성하며, MVVM 구조에서 코드비하인드 없이 사용자 상호작용을 구현하기 위해 사용됩니다. \endif \if EN Encapsulates window drag behavior functionality and related state. \endif
BehaviorCollection
\if KO Attach 메서드: `BehaviorCollection`이 특정 `DependencyObject`에 연결됩니다. `AssociatedObject`가 설정되지 않은 경우에만 연결됩니다. 각 `Behavior`가 `associatedObject`에 Attach 처리됩니다. \endif \if EN Attaches the behavior to a target object. \endif
associatedObject— \if KO 동작 또는 연결 속성을 적용할 종속성 객체입니다. \endif \if EN The dependency object to which the behavior or attached property applies. \endif\if KO Detach 메서드: `BehaviorCollection`을 `associatedObject`에서 분리합니다. 연결된 `Behavior` 항목에 대해 `Detach()`를 호출합니다. \endif \if EN Detaches the behavior from its current target object. \endif
\if KO Associated Object 값을 가져옵니다. \endif \if EN Gets the associated object value. \endif
\if KO associated Object 값을 보관합니다. \endif \if EN Stores the associated object value. \endif
Interaction
\if KO Behaviors 값을 가져옵니다. \endif \if EN Gets the behavior collection attached to the specified object. \endif
obj— \if KO 동작 또는 연결 속성을 적용할 종속성 객체입니다. \endif \if EN The target object. \endif반환: \if KO Get Behaviors 작업에서 생성한 결과입니다. \endif \if EN The attached behavior collection. \endif
\if KO Behaviors Changed 이벤트 또는 상태 변경을 처리합니다. \endif \if EN Handles the behaviors changed event or state change. \endif
obj— \if KO 동작 또는 연결 속성을 적용할 종속성 객체입니다. \endif \if EN The dependency object to which the behavior or attached property applies. \endifargs— \if KO 이벤트와 관련된 데이터를 포함합니다. \endif \if EN Contains data associated with the event. \endif\if KO Behaviors 값을 설정합니다. \endif \if EN Sets the behavior collection attached to the specified object. \endif
obj— \if KO 동작 또는 연결 속성을 적용할 종속성 객체입니다. \endif \if EN The target object. \endifvalue— \if KO 적용할 값입니다. \endif \if EN The behavior collection to attach. \endif\if KO Behaviors Property 값을 보관합니다. \endif \if EN Attached property that stores a behavior collection for a dependency object. \endif
WindowDragBehavior
\if KO Behavior가 Attach될 때 호출됩니다. - `MouseLeftButtonDown` 이벤트를 `AssociatedObject`에 연결하여 드래그 기능을 활성화합니다. \endif \if EN Handles the attached event or state change. \endif
\if KO Behavior가 Detach될 때 호출됩니다. - `MouseLeftButtonDown` 이벤트를 해제하여 드래그 기능을 비활성화합니다. \endif \if EN Handles the detaching event or state change. \endif
\if KO 마우스 왼쪽 버튼을 눌렀을 때 호출됩니다. 연결된 요소가 포함된 Window를 찾아 DragMove를 수행합니다. \endif \if EN Handles the mouse left button down event or state change. \endif
sender— \if KO 이벤트를 발생시킨 객체입니다. \endif \if EN The object that raised the event. \endife— \if KO 마우스 버튼 이벤트 데이터입니다. \endif \if EN Contains data associated with the event. \endif