Hello,
I've noticed that the SL3 Validators automatically uses the properties from DisplayAttribute when creating validation messages. I'm interested in any suggestions on how to extract this information from a control's binding using code. I've included an example:
ViewModel code:
[Display(Name="First Name")]
public string FirstName { get; set; }
I know can achieve this on a Control-by-Control basis doing something like the following (TextBox in this case):
BindingExpression dataExpression = _firstNameTextBox.GetBindingExpression(TextBox.TextProperty)
Type dataType = dataExpression.DataItem.GetType();
PropertyInfo propInfo = dataType.GetProperty(dataExpression.ParentBinding.Path.Path);
DisplayAttribute attr = propInfo.GetCustomAttributes(false).OfType<DisplayAttribute>().FirstOrDefault();
return (attr == null) ? dataExpression.ParentBinding.Path.Path : attr.Name;
I'm interested if there's any way to do this generically, without needing to know the specific type of Control.
Thanks in advance for any thoughts!!