Exposing properties from the custom control
Most of the time, while using custom controls, we need to expose additional properties based on the requirement. In this recipe, we will demonstrate exposing dependency properties from the custom control and binding the record to the UI.
Getting ready
Let's extend our previous project to perform these steps. To get started, launch Visual Studio and open the project CH05.SearchControlDemo
.
How to do it...
Once the project has been opened, perform the following steps to create a dependency property named SearchTerm
and bind it with the control UI:
- Let's open the
SearchControl.cs
to create a dependency property. Inside the class definition, typepropdp
and press the TAB key twice to create the property structure. By default, it generatesMyProperty
of typeint
. - Change the property type from
int
tostring
and press TAB. - Rename
MyProperty
toSearchTerm
and press TAB again. - Now change
ownerclass
toSearchControl
and press TAB. - Pass
string.Empty
as the default...