Extending the functionality of a control using behavior
Behavior is a concept to extend the functionality of a control using a reusable component. These components can be attached to any control or a specific type of control to provide designers with the flexibility to design complex user interactions without writing any additional code.
In this recipe, we will learn how to create a behavior and the way to apply it to a control without writing extra code in the code-behind file.
Getting ready
To get started, we need to open the Visual Studio IDE. Create a new project called CH05.ControlBehaviorDemo
, based on the WPF application template.
How to do it...
Let's start by creating a component which will add a Size Grow
effect to a TextBlock
control when hovering over with the mouse cursor. To do this, perform the following steps:
- To create and/or use behaviors in an application, you will need to set up the project to have a reference to the
System.Windows.Interactivity.dll
assembly file. To do this...