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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:10:07+00:00 2026-06-14T03:10:07+00:00

I’ve read a number of posts on binding Dictionary to WPF ListView and ListBox

  • 0

I’ve read a number of posts on binding Dictionary to WPF ListView and ListBox but I can’t get equivalent code to work in WinRT.

<Grid Margin="10" Width="1000" VerticalAlignment="Stretch">
        <ListBox Name="StatListView" ItemsSource="{Binding FooDictionary}" >
            <ListBox.ItemTemplate>
                <DataTemplate >
                    <Grid Margin="6">
                        <StackPanel Orientation="Horizontal" >
                            <TextBlock Text="{Binding Key}" Margin="5" />
                            <TextBlock Text="{Binding Value}" Margin="5" />
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>


    public Dictionary<string, string> FooDictionary
    {
        get
        {
            Dictionary<string, string> temp = new Dictionary<string, string>();
            temp.Add("key1", "value1");
            temp.Add("key2", "value2");
            temp.Add("key3", "value3");
            temp.Add("key4", "value4");
            return temp;
        }
    }

What is the proper binding?

  • 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-14T03:10:08+00:00Added an answer on June 14, 2026 at 3:10 am

    The error in the output window is (trimmed to the most useful part):

    Error: Cannot get 'Key' value (type 'String') from type 
    'System.Runtime.InteropServices.WindowsRuntime.CLRIKeyValuePairImpl`2
    [[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, 
    PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, 
    Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, ....
    

    Internally, WinRT is converting the type to:

    System.Runtime.InteropServices.WindowsRuntime.CLRIKeyValuePairImpl<K, V>
    

    If you add to your DataTemplate:

    <TextBlock Text="{Binding}" Margin="5" />
    

    You’ll see that it emits the above type with String, String.

    However, for some reason, it’s not being properly handled as expected. If you search for that type on the Internet, you’ll see that there’s a documented bug for the issue on Connect.

    A simple work around would be to place your data in a simple object that is not a KeyValuePair:

    List<StringKeyValue> temp = new List<StringKeyValue>();
    temp.Add(new StringKeyValue { Key = "key1", Value = "value1" } );
    temp.Add(new StringKeyValue { Key = "key2", Value = "value2" });
    temp.Add(new StringKeyValue { Key = "key3", Value = "value3" });
    temp.Add(new StringKeyValue { Key = "key4", Value = "value4" });
    
    this.DefaultViewModel["FooDictionary"] = temp;
    
    public class StringKeyValue
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }
    

    As an aside, from a simple test at least, it’s not the Dictionary that’s causing the issue at all, it’s the fact that it’s a KeyValuePair object instance that’s being converted to the CLRIKeyValuePairImpl type mentioned above. I tried just using a list and adding a KeyValuePair<string, string> instance to a List, and that failed as well.

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

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary

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.