user2686299
user2686299

Reputation: 427

Adding custom property to any control

For example, we have TextBlock control, how can I add to it my own property, it's may looks like <TextBlock MyProperty="666"/> Thanks!

Upvotes: 0

Views: 40

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292765

You can use an attached property, that's exactly what they're here for.

The code won't look exactly as in your example, though, but rather like this:

<TextBlock my:MyClass.MyProperty="666"></TextBlock>

(my is the XML namespace prefix for the namespace where MyClass is declared)

Upvotes: 1

Related Questions