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

DataTemplate

1 Answer 132 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Craig Neblett
Top achievements
Rank 1
Craig Neblett asked on 23 Nov 2015, 08:13 PM
How would you specify a custom DataTemplate in XAML?

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 25 Nov 2015, 08:23 AM
Hi Craig,

The RadListView component is designed to use different cells in its ItemTemplate. In other words users should use one of the classes described in our Cells article. Here is a sample definition of the RadListView component:

<telerikDataControls:RadListView ItemsSource="{Binding FeaturedExamplesList}"
                                 ItemTapped="ExampleTapped"
                                 BackgroundColor="Transparent">
  <telerikDataControls:RadListView.ItemStyle>
    <listView:ListViewItemStyle BackgroundColor="Transparent" BorderWidth="0"/>
  </telerikDataControls:RadListView.ItemStyle>
  <telerikDataControls:RadListView.SelectedItemStyle>
    <listView:ListViewItemStyle BackgroundColor="#E5EDF3" BorderWidth="0"/>
  </telerikDataControls:RadListView.SelectedItemStyle>
  <telerikDataControls:RadListView.PressedItemStyle>
    <listView:ListViewItemStyle BackgroundColor="#E5EDF3" BorderWidth="0"/>
  </telerikDataControls:RadListView.PressedItemStyle>
  <telerikDataControls:RadListView.LayoutDefinition>
    <listView:ListViewLinearLayout Orientation="Horizontal" HorizontalItemSpacing="0"/>
  </telerikDataControls:RadListView.LayoutDefinition>
  <telerikDataControls:RadListView.ItemTemplate>
    <DataTemplate>
      <listView:ListViewTemplateCell>
        <listView:ListViewTemplateCell.View>
          <StackLayout Padding="16, 0, 0, 0" StackLayout.Spacing="8">
            <Image Source="{Binding ImageSourceUri}"
                   HorizontalOptions="Center"
                   Aspect="AspectFit"
                   VerticalOptions="Center">
            </Image>
            <Label Text="{Binding Title}"
                   HorizontalOptions="Start"
                   TextColor="#1E323F">
              <Label.FontSize>
                <OnPlatform x:TypeArguments="x:Double"
                            iOS="17"
                            Android="16"/>
              </Label.FontSize>
            </Label>
          </StackLayout>
        </listView:ListViewTemplateCell.View>
      </listView:ListViewTemplateCell>
    </DataTemplate>
  </telerikDataControls:RadListView.ItemTemplate>
</telerikDataControls:RadListView>
I hope this information is helpful. Please do not hesitate to contact us if you encounter any other issues.

Regards,
Pavel R. Pavlov
Telerik
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
Craig Neblett
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or