Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4340860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:24:23+00:00 2026-05-21T11:24:23+00:00

In my view model, I have added DisplayAttributes to my properties, and would now

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:24:24+00:00Added an answer on May 21, 2026 at 11:24 am

    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 Descriptions property 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:

    <Grid >
        <StackPanel>
            <TextBox Text="{Binding FirstName}" ToolTip="{Binding Descriptions[FirstName]}"/>
            <TextBox Text="{Binding LastName}" ToolTip="{Binding Descriptions[LastName]}"/>
        </StackPanel>
    </Grid>
    

    the code-behind:

            DataContext = new DisplayViewModel();
    

    and a rudimentary view-model with two properties:

    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; }
    
        [Display(Name = "Last Name")]
        public string LastName { get; set; }
    
        public IDictionary<string, string> Descriptions { get { return descriptions; } }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view model that has a property that looks like this Property
I have a DataGrid bound to a PagedCollectionview property of my View-Model. I've added
So I have a view model like so: var viewModel = function() { var
I have a view model coming from the server as json like this {
I have a view model that looks like this public class ViewModelRound2 { public
I have a view model with an Email address property and a Confirm Email
I have a view model with a couple of properties that are not displaying
I have a view model with a property Fields which is an ObservableCollection<FieldVM> .
I have a observable collection exposed as a property within a view model. The
I have a a view model that looks like. public class StoreItemViewModel { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.