Data binding inconsistency

4 posts, 0 answers
  1. Hong
    Hong avatar
    15 posts
    Member since:
    Dec 2012

    Posted 18 Feb 2015 Link to this post

    A WP app has the following:
    <telerikInput:RadListPicker Name="llsCopy" Grid.Row="1" Margin="5" ItemsSource="{Binding listDeviceViewModel}"
                            SelectedItem="{Binding deviceViewModelSelected, Mode=TwoWay}" Header="Copy from:"                                SelectionChanged="llsCopy_SelectionChanged"
                            />


    Handler llsCopy_SelectionChanged can get the selected item by the bound property deviceViewModelSelected without any problem as long as the list is not expanded.  As soon as the is expanded (e.g. when the list size > 5), deviceViewModelSelected is not the selected item anymore.  In this case, I have to use llsCopy.SeletedItem to get the selected item.  It took me a long time to realize this.  I am wondering if this is be design.  
  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 23 Feb 2015 Link to this post

    Hi,

    You need to use SelectedValue and SelectedValuePath. Please, find attached a small example showing this.


    Regards,
    Ves
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Hong
    Hong avatar
    15 posts
    Member since:
    Dec 2012

    Posted 23 Feb 2015 in reply to Ves Link to this post

    Thank you for the response.
    I noticed the sample has the following line:
    SelectedItem="{Binding Paid, Mode=TwoWay}

    Do you mean that in order to use "Paid" as the selected item, one has to add the following two lines:
    SelectedValuePath="SecondValue"
    SelectedValue="{Binding PaidBy, Mode=TwoWay}"

    In other words, one has to use three lines code to bind the selected item correctly.

    Hong
  5. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 26 Feb 2015 Link to this post

    Hi Hong,

    You can use SelectedItem without SelectedValue and SelectedValuePath. You can simply remove these two properties from ListPicker's definition to see what changes in the example. Here is a description:
    • SelectedItem represents an item from the listpicker's items source. If the control is populated with List<string> this would be a string, if ItemsSource is a List<MyObject> the value of SelectedItem would be of type MyObject.
    • SelectedValue and SelectedValuePath work together. If SelectedValuePath is not specified, SelectedValue would be the same as SelectdItem. Else, it SelectedValue would be the value of the property, specified by SelectedValuePath.

    Best regards,
    Ves
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner