user310291
user310291

Reputation: 38190

Can I create equivalent of C# attribute or metadata for WPF child controls in XAML code?

Can I add some kind of custom attributes in XAML ?

Upvotes: 0

Views: 645

Answers (2)

Matěj Zábský
Matěj Zábský

Reputation: 17272

Perhaps you mean Attached properties (scroll down for info on how to create a custom one)? For examle "DockPanel.Dock" is an Attached property.

Or maybe Markup extensions? (though that is something a little bit different)

You can also place Attributes on custom controls and read them in code behind - just like any other .NET class, but that is not possible to do from XAML (since those are set per-type/method/..., not per-instance).

Upvotes: 1

Philip Rieck
Philip Rieck

Reputation: 32568

You can, using Attatched Properties. This lets you add your own and data to the xaml on any control you choose.

Upvotes: 1

Related Questions