Using behaviors WPF/C#
In this small article, I shall demonstrate how to use WPF behavior to add features to UI Controls. All you need is to reference the official System.Windows.Interactivity library or download the NuGet package Expression.Blend.Sdk . Think of behaviors as a piece of code that can do any customization to the UI control without touching the original UI control, it can also be injected on both C# code or XAML. Behaviors have so many useful utilizations, like attaching popup on text boxes to add autocomplete features, inputs validation, styling, … Let me demonstrate : Step 1: creating the behavior Behavior is simply a class inherited from Behavoir<> class, where the generic argument is the UI control type. public class YellowifyBehavior : Behavior<TextBox> { protected override void OnAttached() { AssociatedObject.Background = Brushes.Yellow; } } This is a simple behavior that set the...