In my view model, 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.
I found this SO question which handles the reading of the description, but can’t figure out how to populate the ToolTip using the calculated description.
This seems like a roundabout way to do this since WPF doesn’t support this attribute and so you’ll be entering the attributes into the view-model and the view-model will be looking them up. They could be in any internal format.
In any case, here is a demo of the problem as you’ve stated it. We add a
Descriptionsproperty to the class that the text boxes are bound to. That property is a dictionary that maps property names to descriptions, that is, attributes. In the static constructor for the view-model we look up all the attributes and populate the dictionary.A small XAML file with two text boxes:
the code-behind:
and a rudimentary view-model with two properties: