LiteObservableBehaviors 1.0.0
dotnet add package LiteObservableBehaviors --version 1.0.0
NuGet\Install-Package LiteObservableBehaviors -Version 1.0.0
<PackageReference Include="LiteObservableBehaviors" Version="1.0.0" />
<PackageVersion Include="LiteObservableBehaviors" Version="1.0.0" />
<PackageReference Include="LiteObservableBehaviors" />
paket add LiteObservableBehaviors --version 1.0.0
#r "nuget: LiteObservableBehaviors, 1.0.0"
#:package LiteObservableBehaviors@1.0.0
#addin nuget:?package=LiteObservableBehaviors&version=1.0.0
#tool nuget:?package=LiteObservableBehaviors&version=1.0.0
LiteObservableBehaviors
Lite version of WPF behaviors with fewer features but better performance and a smaller surface area.
Features
- Common WPF
Behavior/TriggerActionimplementations for MVVM bindings. - Lightweight attached behavior patterns.
- Markup extensions for event-to-command bindings.
- XAML namespace:
xmlns:lob="http://schemas.github.com/liteobservablebehaviors/2026/xaml".
Usage
Declare the library namespace and Microsoft.Xaml.Behaviors interactivity namespace in your XAML:
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:b="http://schemas.github.com/liteobservablebehaviors/2026/xaml"
Background: why these two types exist
WPF TextBox exposes properties such as SelectionStart, SelectionLength, SelectedText, and CaretIndex, but they are not dependency properties, so they cannot be bound to a ViewModel through ordinary bindings.
LiteObservableBehaviors addresses this with two complementary types:
| Type | Direction | Role |
|---|---|---|
TextBoxSetStateToControlBehavior |
Source → Control | Push ViewModel values into the TextBox |
TextBoxSetStateToSourceAction |
Control → Source | Push TextBox state back to the ViewModel |
Each instance binds a single property via its Property and Source members.
TextBoxSetStateToControlBehavior
One-way binding from ViewModel to TextBox
When a ViewModel property changes, this behavior writes the new value onto a non-bindable TextBox property such as SelectionStart, SelectionLength, SelectedText, or CaretIndex. Attach one instance per property inside Interaction.Behaviors.
XAML example
<TextBox>
<i:Interaction.Behaviors>
<b:TextBoxSetStateToControlBehavior
Property="SelectionStart"
Source="{Binding CaretPosition}" />
<b:TextBoxSetStateToControlBehavior
Property="SelectionLength"
Source="{Binding SelectionLen}" />
</i:Interaction.Behaviors>
</TextBox>
Behavior
When ViewModel properties such as CaretPosition or SelectionLen raise change notifications (INotifyPropertyChanged), the corresponding TextBox properties are updated automatically.
TextBoxSetStateToSourceAction
One-way push from TextBox to ViewModel
When the user interacts with the TextBox (for example, by changing the selection), this trigger action reads the current control state and writes it to the ViewModel. Place it inside Interaction.Triggers and invoke it from the appropriate event.
XAML example
<TextBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<b:TextBoxSetStateToSourceAction
Property="SelectionStart"
Source="{Binding CaretPosition, Mode=OneWayToSource}" />
<b:TextBoxSetStateToSourceAction
Property="SelectionLength"
Source="{Binding SelectionLen, Mode=OneWayToSource}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
Behavior
Each time SelectionChanged fires, the current SelectionStart and SelectionLength values are written to the bound ViewModel properties.
Combined example (near two-way sync)
Use both types together to approximate two-way synchronization:
<TextBox>
<i:Interaction.Behaviors>
<b:TextBoxSetStateToControlBehavior
Property="SelectionStart"
Source="{Binding CursorPos}" />
<b:TextBoxSetStateToControlBehavior
Property="SelectionLength"
Source="{Binding SelLen}" />
</i:Interaction.Behaviors>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<b:TextBoxSetStateToSourceAction
Property="SelectionStart"
Source="{Binding CursorPos, Mode=OneWayToSource}" />
<b:TextBoxSetStateToSourceAction
Property="SelectionLength"
Source="{Binding SelLen, Mode=OneWayToSource}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
TextBoxBindingSupportBehavior vs SetState types
For TextBox and PasswordBox, TextBoxBindingSupportBehavior offers a simpler approach: bind SelectedText, SelectionLength, and SelectionStart directly with two-way bindings:
<TextBox>
<i:Interaction.Behaviors>
<b:TextBoxBindingSupportBehavior
SelectedText="{Binding SelectedText}"
SelectionLength="{Binding SelectionLength}"
SelectionStart="{Binding SelectionStart}" />
</i:Interaction.Behaviors>
</TextBox>
Prefer TextBoxBindingSupportBehavior when those three properties are all you need. Use the SetStateTo... types when you need other TextBox-specific state (for example CaretIndex) or want finer control over which events drive updates.
Summary
TextBoxSetStateToControlBehavior— add toBehaviors; reflects ViewModel changes on the TextBox (VM → View).TextBoxSetStateToSourceAction— add insideTriggers; sends TextBox state to the ViewModel on events (View → VM).- For common two-way binding of
SelectedText,SelectionLength, andSelectionStart,TextBoxBindingSupportBehavioris the simpler choice.
Project layout
| Path | Purpose |
|---|---|
src/LiteObservableBehaviors.WPF/Observables/ControlBehavior |
SetStateToControlBehavior implementations |
src/LiteObservableBehaviors.WPF/Observables/SourceAction |
SetStateToSourceAction trigger actions |
src/LiteObservableBehaviors.WPF/Observables/ControlBinding |
Two-way binding support behaviors |
src/LiteObservableBehaviors.WPF/Enhancers |
Convenience behaviors (focus, drag-and-drop, etc.) |
src/LiteObservableBehaviors.WPF/Transitions |
Panel transition behaviors |
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net9.0-windows7.0 is compatible. net10.0-windows was computed. net10.0-windows7.0 is compatible. |
| .NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 is compatible. |
-
.NETFramework 4.6.2
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.142)
-
.NETFramework 4.7.2
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.142)
-
.NETFramework 4.8
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.142)
-
.NETFramework 4.8.1
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.142)
-
net10.0-windows7.0
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.142)
-
net8.0-windows7.0
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.142)
-
net9.0-windows7.0
- Microsoft.Xaml.Behaviors.Wpf (>= 1.1.142)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 243 | 7/2/2026 |