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 8922545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:51:50+00:00 2026-06-15T06:51:50+00:00

I have most of the Label objects in my app bound such that they

  • 0

I have most of the Label objects in my app bound such that they can be replaced from a webservice.

I store my replacements in a Dictionary. The replacements vary based on the Client that loaded for the app.

The problem I am having is that most of the time I don’t replace the labels, and the binding failure is throwing an exception that is very slow.

Here is an example: (Note this code functions correctly, it is just slow if it can’t find a match.)

<Label Content="_Gender"
       Helpers:CaptionHelper.PropertyName="Content"
       Helpers:CaptionHelper.PropertyValue="{Binding Labels[Gender], 
                                                     FallbackValue=_Gender}"
       Target="{Binding ElementName=cbGender}" />

When the binding tries to lookup Lables[Gender], I get this in my output window:

System.Windows.Data Warning: 17 : Cannot get 'Item[]' value (type 'String') from 'Labels' (type 'Dictionary`2'). BindingExpression:Path=Labels[Gender]; DataItem='MyViewMV'
      (HashCode=63776763); target element is 'Label' (Name=''); target property is 'PropertyValue'(type 'String') TargetInvocationException:'System.Reflection.TargetInvocationException: 
           Exception has been thrown by the target of an invocation. ---> System.Collections.Generic.KeyNotFoundException: 
           The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Params Truncated)
   at System.Reflection.RuntimeMethodInfo.Invoke(Params Truncated)
   at System.Reflection.RuntimeMethodInfo.Invoke(Params Truncated)
   at MS.Internal.Data.PropertyPathWorker.GetValue(Params Truncated)
   at MS.Internal.Data.PropertyPathWorker.RawValue(Params Truncated)'

Since I have a lot of these, it is taking about a full second to run through them all.

Is there a way to make the binding not throw an exception when the dictionary look up fails? Or somehow fail quicker?

  • 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-15T06:51:52+00:00Added an answer on June 15, 2026 at 6:51 am

    If you have the option to, I would change your IDictionary implementation to one that returns null and instead use TargetNullValue (or even be IDictionary<TKey, object> and return DependencyProperty.UnsetValue if you still use FallbackValue):

    public class PassthruDictionary<TKey, TValue> : IDictionary<TKey, TValue>
    {
        private Dictionary<TKey, TValue> instance;
    
        // ... other stuff
    
        public TValue this[TKey key]
        {
            get
            {
                TValue value;
                if (instance.TryGetValue(key, out value))
                {
                    return value;
                }
                else
                {
                    return default(TValue);
                }
            }
            // ... more
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick one. I'm using mod rewrite and have most replacements in place: empty space
I am currently writing my first Android app and have based most of my
I have a simple ASP.NET MVC 3 dummy app (just learning MVC coming from
I have a custom UIView (MyView) object that gets loaded from a xib file.
I have some code that is looking up group memberships from local groups on
I have a popover screen, with inside it : a label, that may or
well i have most probably an extremly stupid problem but could not figure it
I have spent most of my web-development career in the Microsoft camp, but for
I have the most bizarre bug, where clicking a listbox item makes the listbox
I have the most basic jquery function of them all, but I couldn't find

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.