Introduction
This article demonstrates how to create a Dynamic ListView Application using C# and XAML in Xamarin.Forms.
This article demonstrates how to create a Dynamic ListView Application using C# and XAML in Xamarin.Forms.
Let's start.
Step 1
Open Visual Studio and go to New Project >> installed >> Visual C# >> Cross-Platform.
Select Cross-Platform App, then give your project a name and location.
Step 1
Open Visual Studio and go to New Project >> installed >> Visual C# >> Cross-Platform.
Select Cross-Platform App, then give your project a name and location.

Step 2
After project creation, update the following NuGet Packages to your project.
Xamarin.Forms
Go to Solution Explorer and select your solution. Right-click and select "ManageNuGett Packages for Solution".

Now, select the following NuGet package and select your project to update it.
Step 3
Next, add an image to open Solution Explorer >> projectName.Android >> Resources >> Right click the drawable >>Add >> Existing Item and add the image.
Step 4
Open Solution Explorer >> Project Name >> Mainpage.xaml. Open the Design View of this page.

The code is given below.
XAML Code
Next, add an image to open Solution Explorer >> projectName.Android >> Resources >> Right click the drawable >>Add >> Existing Item and add the image.
Step 4
Open Solution Explorer >> Project Name >> Mainpage.xaml. Open the Design View of this page.

The code is given below.
XAML Code
- <StackLayout Padding="0,20,0,0">
- <Label Text="Dynamic Resizing Demo" FontAttributes="Bold" HorizontalOptions="Center" />
- <ListView x:Name="listView" HasUnevenRows="true">
- <ListView.ItemTemplate>
- <DataTemplate>
- <ViewCell>
- <StackLayout Padding="15,5,5,5" Orientation="Horizontal">
- <Image Source="Image.jpg" HeightRequest="50">
- <Image.GestureRecognizers>
- <TapGestureRecognizer Tapped="OnImageTapped" />
- </Image.GestureRecognizers>
- </Image>
- <Label Text="Flower" VerticalOptions="Center" />
- </StackLayout>
- </ViewCell>
- </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- </StackLayout>


Hafiz IrfanPosted Jul 16, 2020, 12:22 AM
Can we use dynamic template in list view?