Hi,
In my BO, I have added DisplayAttributes to my properties, and would now like to bind the ToolTip property of my TextBox controls to the Description property of the DisplayAttribute.
Is WPF and silverlight support the DisplayAttribute dataAnnotation ?
Here what I'm trying to do:
In my basic class, I have this property :
[Display(Name = "Description")]
public string Description { get; set; }
Below the XAML code. Actually, I don't know how to realize the binding with the ToolTip property of my TextBox controls. That's why I have write XXX.
<TextBox Text="{Binding Description}" ToolTip="{Binding XXX}"/>
Thx in advance for your help,
Cedric
SenthilkumarRank #387 · 6.5K pointsPosted Apr 12, 2012, 10:35 PM EDT
DataContext = new DisplayViewModel(); public class DisplayViewModel { private static Dictionary<string, string> descriptions; static DisplayViewModel() { descriptions = new Dictionary<string,string>(); foreach (var propertyName in PropertyNames) { var property = typeof(DisplayViewModel).GetProperty(propertyName); var displayAttributes = property.GetCustomAttributes(typeof(DisplayAttribute), true); var displayAttribute = displayAttributes.First() as DisplayAttribute; var description = displayAttribute.Name; descriptions.Add(propertyName, description); } } public DisplayViewModel() { FirstName = "Bill"; LastName = "Smith"; } public static IEnumerable<string> PropertyNames { get { return new[] { "FirstName", "LastName" }; } } [Display(Name = "First Name")] public string FirstName { get; set; }public string LastName { get; set; } public IDictionary<string, string> Descriptions { get { return descriptions; } } }