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

  • SEARCH
  • Home
  • 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 8078773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:54:11+00:00 2026-06-05T15:54:11+00:00

I have a Label that translates a code inserted by the user to the

  • 0

I have a Label that translates a code inserted by the user to the description. For that I am using a Dictionary inside a converter.
This Dictionary is filled in every call to the Converter throw a Service. This is a really ugly thing, and I wanted to have this dictionary in my viewmodel but I have no ideia how to access it from the converter.

Any ideia?

  • 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-06-05T15:54:12+00:00Added an answer on June 5, 2026 at 3:54 pm

    In your view, bind the dictionary as a resource (supplied by the ViewModel). Change the converter to an IMultiValueConverter and use a <MultiBinding> to bind it to both the value that you need to use for lookup, and to the dictionary that you’re looking up in.

    See http://msdn.microsoft.com/en-us/library/system.windows.data.imultivalueconverter.aspx for more information on converters taking multiple input values, and an example of using one with a <MultiBinding>.

    Alternatively, as GazTheDestroyer proposed, put it in your ViewModel.

    class MyViewModel : INotifyPropertyChanged
    {
    
       public MyViewModel()
       {
          // Call service to populate _dictionary here...
       }
    
       private Dictionary<string, string> _dictionary;
       private string _code;
    
       public string Code
       {
          get { return _code; }
          set
          {
             _code = value;
             Description = _dictionary[_code];
             if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("Description"));
          }
       }
    
       public string Description { get; set; }
    }
    

    And instead of binding through a converter, bind to the Description property.

    UPDATE

    To answer your question about updating, you’ll need to change the binding in your XAML slightly to change the UpdateSourceTrigger. The default for a Text property is to update when the control loses focus, this will change it to every time the value changes:

    <TextBox Text="{Binding Code,UpdateSourceTrigger=PropertyChanged}" />
    

    Further reading is available at http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger.aspx

    You may have to add some error validation here – every keystroke will alter the value of Description so you may want to include some logic in your ViewModel to only change the value when there is a value to use, or grey out a value that does not correspond to the (half-finished) code. These are usability things though, you can play around to find what is best for your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a label that is using a repeater to get information form a
i have this crazy label for each time i create a migration that use
I have panel that is using group layout to organize some label. I want
I have this code: $('#label, #btlabel').live('hover',function(){ parent = $(this).parent().attr('id'); position = $(this).parent().position(); positionTop =
I have a code pattern which translates one integer to another. Just like this:
I have a Label that looks the following: <Label Name=FalsePositiveInput Content=&#x2713;> This works but
I have a label that is sometimes empty. How do I set up a
I have a label that gets updated with values calculated from information received by
I have a label on a splash screen that is displayed for 4 seconds.
I have several label boxes on my design form that all share the naming

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.