- Home
- Forum
- Xamarin.Forms
- ListView selection not working properly
ListView selection not working properly
I have an ItemTemplate and and SelectedItemTemplate, where each item is supposed to turn orange when selected. However, selecting in most places on the list selects one of the first three items, and then when I scroll down, the bottom three are selected, scroll up, and the top three are also all suddenly selected. I cannot specifically and reliably select anything else.
Here is my code:
______________________________________________________________________________
<StackLayout Padding="20" BackgroundColor="White">
<listview:SfListView x:Name="listView" IsScrollingEnabled="True" ItemSpacing="0,10"
SelectionMode="Multiple" SelectionBackgroundColor="Transparent">
<listview:SfListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Subject</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subject</x:String>
</x:Array>
</listview:SfListView.ItemsSource>
<listview:SfListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame CornerRadius="45" BackgroundColor="LightBlue" Padding="20,10"
HasShadow="False">
<StackLayout VerticalOptions="FillAndExpand">
<Label Text="{Binding .}"
TextColor="Black"/>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</listview:SfListView.ItemTemplate>
<listview:SfListView.SelectedItemTemplate>
<DataTemplate>
<ViewCell>
<Frame CornerRadius="45" BackgroundColor="Orange" Padding="20,10"
HasShadow="False">
<StackLayout VerticalOptions="FillAndExpand">
<Label Text="{Binding .}"
TextColor="White"/>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</listview:SfListView.SelectedItemTemplate>
</listview:SfListView>
</StackLayout>
<listview:SfListView x:Name="listView" IsScrollingEnabled="True" ItemSpacing="0,10"
SelectionMode="Multiple" SelectionBackgroundColor="Transparent">
<listview:SfListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Subject</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subject</x:String>
<x:String>Subjecte</x:String>
<x:String>Subject</x:String>
<x:String>Subject</x:String>
</x:Array>
</listview:SfListView.ItemsSource>
<listview:SfListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame CornerRadius="45" BackgroundColor="LightBlue" Padding="20,10"
HasShadow="False">
<StackLayout VerticalOptions="FillAndExpand">
<Label Text="{Binding .}"
TextColor="Black"/>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</listview:SfListView.ItemTemplate>
<listview:SfListView.SelectedItemTemplate>
<DataTemplate>
<ViewCell>
<Frame CornerRadius="45" BackgroundColor="Orange" Padding="20,10"
HasShadow="False">
<StackLayout VerticalOptions="FillAndExpand">
<Label Text="{Binding .}"
TextColor="White"/>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</listview:SfListView.SelectedItemTemplate>
</listview:SfListView>
</StackLayout>
_____________________________________________________________________
This issue is stopping my progress pretty badly - I'd very much like to use the SfListView over the standard Xamarin controls, but no use in a list if I can't select most items on it.
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
LN
Lakshmi Natarajan
Syncfusion Team
June 4, 2020 10:18 AM UTC
Hi Caleb,
Thank you for using Syncfusion products.
We have checked the reported query “ListView selection not working properly” from our end. We would like to inform you that the SfListView do the value comparison for selection based on the BindingContext. To achieve this, we suggest you to bind the ItemsSource collection using MVVM concept. Also, bind the model property to the ListViewItem. Please refer the following document to bind the data to the ListView from the following link,
UG link: https://help.syncfusion.com/xamarin/listview/getting-started#adding-the-sflistview-in-xamarinforms
Please let us know if you need further assistance.
Regards,
Lakshmi Natarajan
Marked as answer
SIGN IN To post a reply.