Dictionary binding to ListBox Control

2 posts, 0 answers
  1. Dharmavaram
    Dharmavaram avatar
    99 posts
    Member since:
    Jun 2013

    Posted 15 Sep 2016 Link to this post


        I am trying to bind dictionary object to ListBoxControl as shown below

             <telerik:RadListBox ItemsSource="{Binding Path=BooksAvailable}" Height="270">
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding Path=Value}"
                           Width="20" />
                        <TextBlock Text="{Binding Path=Key}"
                           Width="100" />

          I want to do two way binding of the values so that if user unchecked I have to update internal Boolean value property.But it is giving exception two way binding can't be possible with dictionary value.

    Please help to resolve this.




  2. Polya
    Polya avatar
    242 posts

    Posted 19 Sep 2016 Link to this post

    Hello Nagasree,

    The issue is caused by the two-way binding with the read-only property Value - which is not supported:
    "System.Windows.Markup.XamlParseException: A TwoWay or OneWayToSource binding cannot work on the read-only property 'Value' of type 'System.Collections.Generic.KeyValuePair`2[System.String,System.Boolean]'":

    Because the two-way binding is not supported in the Microsoft's implementation of the KeyValuePair you can either use one-way binding with property Value or use an ObservableCollection<Custom_Class> instead of Dictionary.

    I've prepared a sample project demonstrating the second approach. Please find it attached.

    Hope this helps.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top