Not able to bind data to RadListView

7 posts, 1 answers
  1. Vaibhav
    Vaibhav avatar
    11 posts
    Member since:
    Nov 2016

    Posted 25 Jan Link to this post

    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>

  2. Answer
    Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    359 posts

    Posted 25 Jan Link to this post

    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
  3. Vaibhav
    Vaibhav avatar
    11 posts
    Member since:
    Nov 2016

    Posted 27 Jan in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Thank you Lance. Its working now. Thanx for your quick support.
  4. Vaibhav
    Vaibhav avatar
    11 posts
    Member since:
    Nov 2016

    Posted 27 Jan Link to this post

    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).
  5. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    359 posts

    Posted 27 Jan Link to this post

    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
  6. Vaibhav
    Vaibhav avatar
    11 posts
    Member since:
    Nov 2016

    Posted 31 Jan Link to this post

    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,
  7. Tsvyatko
    Admin
    Tsvyatko avatar
    857 posts

    Posted 01 Feb Link to this post

    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
Back to Top