Reputation: 15
I tried creating a listView with a button inside it in xamarin UWP but i am getting a blank output window. I tried something like this
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Button Text="CLick"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Help me to create a list view in xamarin UWP. If any errors, correct me. Thanks in advance
Upvotes: 1
Views: 300
Reputation: 3217
This example will show a single Button inside a ListView. This way you directly add the Button as children.
<ListView>
<Button Text="CLick"/>
</ListView>
This should also work with multiple children.
<ListView>
<Button Text="CLick"/>
<Button Text="CLick2"/>
</ListView>
This example will show a collection of buttons in your listview. The number of buttons depends on how many items there are in your collection. You need to make use of the ItemsSource Property.
In your code behind / viewmodel you'll need some IENumerable/ICollection type named ListViewItems that holds atleast one element.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App1.Views.ListViewExample">
<ContentPage.Content>
<ListView ItemsSource="{Binding ListViewItems}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Button Text="CLick"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
Further Explanation
For each item in your bound collection a Grid with a Button as child will be created.
Upvotes: 3