views:

42

answers:

1

Is there a way in WPF to Databind to a System.Attribute which is attached to a proerty on A ViewModel. For Example I have some properties on a my ViewModel class. These classes have attributes that define the fields label text or caption. Is there a way to databind to the value in the attribute. In the example below I want to use databinding to extract the caption attributes CaptionText value.

public class Person
{
   [Caption(CaptionText:="First Name")]
   public FirstName {get;set;}
}

Thanks for your help.

Update: Creating a ValueConverter worked for me. I will update this with some source soon.

+2  A: 

The only way I could think of doing it is to bind to the whole object (i.e. {Binding}) and then use a ValueConverter to extract the attribute information using reflection (using GetCustomAttributes).

Steven Robbins