query

858Currently online
81Today's Reading
43Share Today
Multilingual display

WPF dependency properties: [1] Add simple dependency properties

2018-04-12 20:48:25

The importance of dependency properties in WPF programming is well known, and the concept is not outlined or explained here. Detailed introduction to view blog.csdn.net/rabbitsoft_1987/article/details/18240171. This article explains how to define a simple dependency attribute. The implementation function is to customize MyLabel, add Caption dependent property, the content is displayed as Caption value, and bind the Caption property of MyLabel to the Text content of TextBox. When the Text changes, the content of MyLabel will be modified.

Tools/Materials
1

Platforms Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server

2

2008 (Server core not supported), Windows Server 2008 R2 (Server core SP1 or later supported), Windows Server 2003

3

SP2

4

.NET version.NET Framework Supported by the following versions: 4, 3.5, 3.0.NET Framework Client Profile Supported by the following versions: 4, 3.5 SP1  

Methods/Steps
1

Creating a MyLabel control adds the Caption dependency property to the MyLabel control, binding the Content of the Label control to the newly defined Caption dependency property. ps: Typing propdp in the background code (*.cs) and then Tab will create the dependency property definition template.

2

Use the MyLabel control to bind the Caption property of the MyLabel control to the Text property of the text box.

3

This page is based on experience

Recommendation