Core infrastructure for implementing MVVM Behaviors in WPF within the Dreamine framework.
This library provides the base abstractions required to build reusable attached behaviors that can be applied to WPF UI elements.
It is intended to be used as the foundation layer for higher-level behavior packages such as:
- Dreamine.MVVM.Behaviors
- Dreamine.MVVM.Triggers
- Dreamine.MVVM.Interactions
WPF behaviors allow UI logic to be attached to controls without breaking the MVVM pattern.
However, many implementations rely on heavy frameworks or implicit behavior systems.
Dreamine.MVVM.Behaviors.Core provides a minimal and explicit infrastructure to build behaviors with:
- strong typing
- predictable attach/detach lifecycle
- clean MVVM separation
Generic base class for creating behaviors.
Features:
- Strongly typed
AssociatedObject - Based on
Freezablefor XAML support - Explicit attach / detach lifecycle
- Designed for MVVM-friendly UI extensions
Example target types:
WindowButtonTextBoxGrid
Interface that represents an object that can attach to a DependencyObject.
Responsibilities:
- Manage reference to the attached UI element
- Handle lifecycle of connection and disconnection
Methods:
Attach(DependencyObject)
Detach()
Core contract for all Dreamine behaviors.
Defines the minimal structure required for any behavior implementation.
Dreamine.MVVM.Behaviors.Core
│
├─ Base
│ └─ BehaviorGeneric.cs
│
├─ Interfaces
│ ├─ IAttachedObject.cs
│ └─ IBehavior.cs
│
└─ Dreamine.MVVM.Behaviors.Core.csproj
WPF UI Element
│
└─ Behavior<T>
│
├─ Attach()
└─ Detach()
This design allows behaviors to extend UI functionality while keeping ViewModel logic completely separate.
Example behavior skeleton:
public class FocusBehavior : Behavior<TextBox>
{
protected override void OnAttached()
{
AssociatedObject.Focus();
}
protected override void OnDetaching()
{
}
}Usage in XAML:
<TextBox>
<i:Interaction.Behaviors>
<local:FocusBehavior/>
</i:Interaction.Behaviors>
</TextBox>Runtime:
.NET 8.0
WPF
- Dreamine.MVVM.Behaviors
- Dreamine.MVVM.Attributes
- Dreamine.MVVM.ViewModels
MIT License