This is a migrated thread and some comments may be shown as answers.

Data binding inconsistency

3 Answers 45 Views
ListPicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hong
Top achievements
Rank 1
Hong asked on 18 Feb 2015, 07:33 PM
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.  

3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 23 Feb 2015, 11:47 AM
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.

 
0
Hong
Top achievements
Rank 1
answered on 23 Feb 2015, 03:11 PM
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
0
Ves
Telerik team
answered on 26 Feb 2015, 01:05 PM
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.

 
Tags
ListPicker
Asked by
Hong
Top achievements
Rank 1
Answers by
Ves
Telerik team
Hong
Top achievements
Rank 1
Share this question
or