question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlowListView is not updating when remove an item

See original GitHub issue

Hi guys!

I have a simple scenario which a user can add and remove items from a ObservableCollection in MVVM app.

I have an issue when I have two or more items and remove one item. The UI is not updating. But when all items are removed from ObservableCollection, then the UI is updated clearing the list.

Take a look in the demo: listview

Here is the (resumed) code:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
			 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
			 xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
			 prism:ViewModelLocator.AutowireViewModel="True"
			 xmlns:converters="clr-namespace:MyApp.Converters;assembly=MyApp"
			 x:Class="MyApp.Views.MyPage"
			 x:Name="MyPage">

	<ContentPage.Resources>
		<ResourceDictionary>
			<converters:UrlToImageSourceConverter x:Key="UrlToImageSource" />
		</ResourceDictionary>
	</ContentPage.Resources>

	<StackLayout HorizontalOptions="FillAndExpand" >

		<controls:FlowListView FlowColumnCount="3" 
							SeparatorVisibility="None" VerticalOptions="Start"
							HasUnevenRows="True"									
							FlowItemsSource="{Binding Images}">
			<controls:FlowListView.FlowColumnTemplate>
				<DataTemplate>
					<StackLayout Padding="0,0,0,0">
						<Image Source="{Binding Url, Converter=UrlToImageSource}" HeightRequest="90" Margin="0,5,0,5" />
						<Button Text="Remove" 
								Command="{Binding Source={x:Reference MyPage}, Path=BindingContext.RemoveImageCommand}" 
								CommandParameter="{Binding .}"/>
					</StackLayout>
				</DataTemplate>
			</controls:FlowListView.FlowColumnTemplate>
		</controls:FlowListView>

	</StackLayout>
</ContentPage>


public class MyPageViewModel : BindableBase
{
	private ObservableRangeCollection<MyImage> _imageList = new ObservableRangeCollection<MyImage>();


	public DelegateCommand<MyImage> RemoveImageCommand => new DelegateCommand<MyImage>(item => _imageList.Remove(item) );
	//...

	public ObservableRangeCollection<MyImage> Images
	{
		get { return _imageList; }
		set { SetProperty(ref _imageList, value); }
	}

}

public class MyImage
{
	public string Url { get; set; }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
NelsonSantoscommented, Feb 20, 2017

+1 Here!!

But, I maked a workaround to solve this until a solution:

1 - Remove the item 2 - Make a copy of your collection 3 - Set this copy in your ObservableCollection at your model

This make to FlowListItens.FlowItemsSource to know that have new collection and refresh the data.

Regards…

Nelson

0reactions
levelfivecodercommented, Nov 3, 2019

+1 Here!!

But, I maked a workaround to solve this until a solution:

1 - Remove the item 2 - Make a copy of your collection 3 - Set this copy in your ObservableCollection at your model

This make to FlowListItens.FlowItemsSource to know that have new collection and refresh the data.

Regards…

Nelson

not working

Read more comments on GitHub >

github_iconTop Results From Across the Web

FlowListView not fully updating UI when changing ...
When I remove objects from the list the UI doesn't reflect the current state of the list, normally failling by only one item....
Read more >
Nested ListView is not updating the delete action on a ...
Hello support, I have the following problem in my ASP.Net WebForms devexpress application. I got a nested list view in a popup window, ......
Read more >
ListView - .NET MAUI
If the ListView is required to refresh as items are added, removed, or changed in the underlying collection, the underlying collection ...
Read more >
ListView
The ListView widget is an extremely useful widget for displaying a list of items in a linear arrangement (vertical or horizontal).
Read more >
Use Flows to Bulk Update Records from List View in ...
In this article, I am going to show how can we remove duplicate records from collection variables or de-duplicate collection variables in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found