locked
How to binding combobox with Dictionary ? RRS feed

  • Question

  • My data source definition as below. Type of FinincialNewsCategories is Dictionary<string, string>

    <UserControl.Resources>
            <CollectionViewSource
                x:Name="financialNewsCategoriesViewSource"
                Source="{Binding FinancialNewsCategories}"
                IsSourceGrouped="False"
                d:Source="{Binding FinancialNewsCategories, Source={d:DesignInstance Type=vm:FinancialNewsGroupItemsViewModel, IsDesignTimeCreatable=True}}"/>
        </UserControl.Resources>

    And my comboBox binding

    <ComboBox x:Name="FinancialNewsCategoryComboBox"
                          DisplayMemberPath="Value"
                          ItemsSource="{Binding Source={StaticResource financialNewsCategoriesViewSource}, Mode=OneWay}"
                          SelectedItem="{Binding SelectedValue, Mode=TwoWay}" />

    I have two questions

    1. this xaml works fine at Designtime, but shows nothing at Runtime. why ? (If I remove DisplayMemberPath="Value" then I will see type string at runtime)
    2. Onece I add SelectedValuePath(for example: SelectedValuePath = "Key") then nothing will show both DesignTime and Runtime. So when and how to use SelectedValuePath attribute ?

    I have searched the internet and find many WPF solution to this problem. but nothing works.

    Wednesday, August 1, 2012 6:22 AM

Answers

  • I was able to reproduce this on RP but not on RTM bits.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, August 8, 2012 8:28 PM
    Moderator

All replies

  • Do you mind sending a working reproduction app to me?  MSMALL at Microsoft.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Wednesday, August 1, 2012 6:55 PM
    Moderator
  • Hi~ OK~ I'll send you my solution.
    (sent from PONPON66 at hotmail  and title as SourceCode)

    thanks for your help.

    Thursday, August 2, 2012 8:28 AM
  • Hi Matt,

    Did you receive my mail ?

    Friday, August 3, 2012 10:03 AM
  • Yes, I will look at this today.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Friday, August 3, 2012 1:42 PM
    Moderator
  • I was able to reproduce this on RP but not on RTM bits.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, August 8, 2012 8:28 PM
    Moderator