I have a scenario where I binding to the SfListView using the MVVM pattern. I do a search which changes the items the list is bound too. Everything changed; however, it looks like the control does not get cleared out properly. It almost seems like a UI virtualization issue. Here is the scenario.
Step #1 - Search returns a list of 1 item.
Result: One item shown in list.
Step #2 - Search returns a list of 100 items.
Result: 100 items shown in the list. List is scrollable for all items.
Step #3 - Repeat Step #1 search.
Result: Many items shown in the list with the first item being the results from Step #1 and the remaining onscreen items from Step #2. List is not scrollable since it seems to think that there is only one item (which there should be) in the list but there are many other items shown on screen.
*** XAML below ***
<StackLayout Margin="15">
<SearchBar x:Name="searchBar"
Placeholder="Enter name of swimmer"
SearchCommand="{Binding SearchCommand}"
SearchCommandParameter="{Binding Source={x:Reference searchBar}, Path=Text}"
TextChanged="SearchBar_OnTextChanged"/>
<sync:SfListView x:Name="listView"
Margin="0"
Padding="0"
SelectionMode="Single"
BackgroundColor="#F0F0F0"
ItemSpacing="5,5,5,0"
IsScrollBarVisible="False"
ItemsSource="{Binding Swimmers}">
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Text="{Binding FullName}" Style="{DynamicResource TitleStyle}" />
<Label Grid.Column="0" Grid.Row="1" Text="{Binding ClubCode}" Style="{DynamicResource SubtitleTextStyle}" />
</Grid>
<sync:SfListView.ItemSize>
<OnPlatform x:TypeArguments="x:Double">
<OnPlatform.Android>
<OnIdiom x:TypeArguments="x:Double"
Phone="60"
Tablet="60" />
</OnPlatform.Android>
<OnPlatform.iOS>
<OnIdiom x:TypeArguments="x:Double"
Phone="60"
Tablet="60" />
</OnPlatform.iOS>
</OnPlatform>
</sync:SfListView.ItemSize>
<sync:SfListView.ItemTemplate>
<DataTemplate>
<Frame CornerRadius="0" OutlineColor="CornflowerBlue" Padding="8" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Text="{Binding FullName}" Style="{DynamicResource TitleStyle}" />
<Label Grid.Column="0" Grid.Row="1" Text="{Binding ClubCode}" Style="{DynamicResource SubtitleTextStyle}" />
</Grid>
</Frame>
</DataTemplate>
</sync:SfListView.ItemTemplate>
</sync:SfListView>
<!--<ListView ItemsSource="{Binding Swimmers}"
HasUnevenRows="true"
ItemTapped="OnListViewItemTapped"
ItemSelected="OnListViewItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Text="{Binding FullName}" Style="{DynamicResource TitleStyle}" />
<Label Grid.Column="0" Grid.Row="1" Text="{Binding ClubCode}" Style="{DynamicResource SubtitleTextStyle}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>-->
</StackLayout>
*** C# code below ***
public List<Swimmer> Swimmers
{
get => _swimmers;
private set
{
_swimmers = value;
Device.BeginInvokeOnMainThread(() =>
{
RaisePropertyChanged(()=> Swimmers);
});
}
}
Attachment:
Archive_c560b5fd.zip