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

Not able to bind data to RadListView

6 Answers 246 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Vaibhav
Top achievements
Rank 1
Vaibhav asked on 25 Jan 2017, 04:54 PM

Hello guys,

I am facing issue with binding the contents to the RadListView.

I am doing it as follows,

<telerikDataControls:RadListView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="uiListView" ItemsSource="{Binding Assets}">

                                                                             <!--'Assets' is the list of asset.-->

            <telerikDataControls:RadListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                  <ViewCell.View>
                    <StackLayout>
                      <Grid Padding="10,10,10,0">

                        <Label Grid.Row="0" Grid.Column="0" Text="{Binding AssetNumber}" FontSize="14" FontAttributes="Bold" LineBreakMode="NoWrap"/>

                       </Grid>
                    </StackLayout>
                  </ViewCell.View>
                </ViewCell>
              </DataTemplate>
            </telerikDataControls:RadListView.ItemTemplate>

            <telerikDataControls:RadListView.SelectedItemStyle>
              <telerikListView:ListViewItemStyle BackgroundColor="#88888888"/>
            </telerikDataControls:RadListView.SelectedItemStyle>
          </telerikDataControls:RadListView>

6 Answers, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 25 Jan 2017, 05:49 PM
Hello Vaibhav,

If you want to have a custom cell, you need to use the ListViewTemplateCell, find the documentation here.

Here is your DataTemplate, updated for use with the RadListView:

<telerikDataControls:RadListView.ItemTemplate>
    <DataTemplate>
        <listView:ListViewTemplateCell>
            <listView:ListViewTemplateCell.View>
                <Grid Padding="10,10,10,0">
                    <Label Grid.Row="0" Grid.Column="0" Text="{Binding AssetNumber}" FontSize="14" FontAttributes="Bold" LineBreakMode="NoWrap"/>
                </Grid>
            </listView:ListViewTemplateCell.View>
        </listView:ListViewTemplateCell>
    </DataTemplate>
</telerikDataControls:RadListView.ItemTemplate>

Seeing your template, I recommend trying the ListViewTextCell as it provides both a main Text and Detail text binding option with well formatted styling out-of-the-box.

Lastly, I see that you're adding some padding for the item, you can also use the VerticalItemSpacing feature of the RadListView to get  the desired amount of spacing between items. See here for example code and screenshots.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Vaibhav
Top achievements
Rank 1
answered on 27 Jan 2017, 09:46 AM
Thank you Lance. Its working now. Thanx for your quick support.
0
Vaibhav
Top achievements
Rank 1
answered on 27 Jan 2017, 02:17 PM
Hello @Lance, As I am still working on RadListView, I am facing one more problem. How do I show any of the item in the list as selected (i.e with checkbox checked).
0
Lance | Manager Technical Support
Telerik team
answered on 27 Jan 2017, 03:46 PM
Hello Vaibhav,

You're already doing it with the SelectedItemStyle, please take a look at this page in the documentation for further guidance op Selection and here for selected item styling..

This also depends on the platform specific UI guidance. If you run the app on iOS, you will see checkboxes for the selected items when in multiple selection mode, this is the expected UI guidance for iOS.

If you need to have a custom setup and have checkboxes on every platform, then you'll need to do two things:

- Add an "IsSelected" property to the model
- Add a checkbox to the item template, bound to the IsSelected property
- Toggle the IsSelected value in the selection changed event.

Is there a relationship between that button you've added to the ItemTemplate and the IsSelected? If you are making the selection using that button, you can easily toggle the IsSelected value there as well.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Vaibhav
Top achievements
Rank 1
answered on 31 Jan 2017, 02:38 PM
Hello Lance,

Is it possible to databind to the SelectedItems property of RadListView in case of edit a form. I want to display an item as selected when the RadListView load.

Please let me know your reply on this.

Thanks,
0
Tsvyatko
Telerik team
answered on 01 Feb 2017, 07:15 AM
Hi Vaibhav,

Currently, Selected items are not bindable properties. As a result you can bind it to your viewmodel only through attached property or behavior by passing the selected property instance and assigning it to your viewmodel property (Simulation one way to source binding).

This is a requested feature and it is logged in our feedback portal You can track its progress and vote for it.


Regards,
Tsvyatko
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ListView
Asked by
Vaibhav
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Vaibhav
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or