Hi I am trying to update listView
by adding and removing item from it. Adding Item in listview
works fine in iOS and android well. But removing any item from it gives wrong out on android, it works perfect on iOS.
In Android : whenever I delete a item from listview it deletes from collection but on UI it deletes last item present on UI after deleting when I add once again it adds previously deleted item into list not new new fresh item. Please check code I used
<ListView RowHeight="100" HorizontalOptions="End" ItemsSource="{Binding GuidePrices, Mode=OneWay}" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal">
<controls:BindablePicker ItemsSource="{Binding Prices}" WidthRequest="150" SelectedItem="{Binding SelectedProduct, Mode=TwoWay}" />
<Button Text="Add" IsVisible="{Binding Action}">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand CommandNameContext="{b:RelativeContext CampsiteViewPage}"
EventName="Clicked"
CommandName="AddPriceListCommand"
CommandParameter="{Binding}" />
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</Button>
<Button Text="Delete" IsVisible="{Binding Action, Converter={StaticResource cnvInvert}}">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand CommandNameContext="{b:RelativeContext CampsiteViewPage}"
EventName="Clicked"
CommandName="DeletePriceListCommand"
CommandParameter="{Binding}" />
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</Button>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
--ViewModel code for on add and delete command
this.AddPriceListCommand = new Command((s) =>
{
if (_guidePrices != null)
{
_guidePrices.Add(new PricesListModel() { ListId = Guid.NewGuid(), Action = false, Prices = _campsite.Guides[0].Prices });
}
});
this.DeletePriceListCommand = new Command((sender) => {
var _priseList = (from priceList in _guidePrices
where priceList == (PricesListModel)sender
select priceList).ToList();
_guidePrices.RemoveAt(_guidePrices.IndexOf((PricesListModel)sender));
});
I am not able find cause why this behave on android as same code works in ios as expected.