Xamarin表单xaml Listview不随集合更改而更新
您好,我正在尝试通过添加和删除列表视图中的项来更新列表视图。在listview中添加项在iOS和android中效果良好。但在安卓系统上删除任何项目都会产生错误,它在iOS上运行得非常完美。 在Android中:每当我从listview中删除一个项目时,它都会从集合中删除,但在UI上,它会删除删除后出现在UI上的最后一个项目。当我再次添加时,它会将以前删除的项目添加到列表中,而不是新的项目。请检查我使用的代码Xamarin表单xaml Listview不随集合更改而更新,xaml,listview,xamarin,xamarin.android,xamarin.forms,Xaml,Listview,Xamarin,Xamarin.android,Xamarin.forms,您好,我正在尝试通过添加和删除列表视图中的项来更新列表视图。在listview中添加项在iOS和android中效果良好。但在安卓系统上删除任何项目都会产生错误,它在iOS上运行得非常完美。 在Android中:每当我从listview中删除一个项目时,它都会从集合中删除,但在UI上,它会删除删除后出现在UI上的最后一个项目。当我再次添加时,它会将以前删除的项目添加到列表中,而不是新的项目。请检查我使用的代码 <ListView RowHeight="100" HorizontalOpt
<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>
我找不到android上出现这种情况的原因,因为同样的代码在ios上也能正常工作。什么类型的价格?从列表中删除项目不会更新UI。您需要使用ObservaleCollection或raise PropertyChanged event notify UI来更新什么是\u指南价格类型?从列表中删除项目不会更新UI。您需要使用ObservaleCollection或raise PropertyChanged event notify UI来更新您使用的是什么Xamarin.Forms版本?以下是我对Xamarin Xamarin 3.9.519.0 5667ef4 Xamarin.Android 4.20.0.37 Xamarin.iOS 8.8.1.0 Xamarin.iOS的VS配置统一迁移1.0您使用的Xamarin.Forms版本是什么?这是我的Xamarin Xamarin 3.9.519.0 5667ef4 Xamarin.Android 4.20.0.37 Xamarin.iOS 8.8.1.0 Xamarin.iOS统一迁移1.0是的,我使用的是“ObservaleCollection”,我的listview也会更新,但每当我删除列表中的中间项时,它就会从UI中删除最后一项。另外,当我添加新项目而不是添加新项目时,它会在末尾添加已删除的项目。删除可观察集合中的ok。它在iOS中正常工作。安卓平板电脑不明白为什么。请不要猜测安卓系统中的这种行为,以便我可以解决。我不知道,我将不得不在我的机器上试用它。我使用的是“ObservaleCollection”,我的列表视图也会更新,但每当我删除列表中的中间项时,它就会从UI中删除最后一项。另外,当我添加新项目而不是添加新项目时,它会在末尾添加已删除的项目。删除可观察集合中的ok。它在iOS中正常工作。我不明白为什么要用android平板电脑。Prashant对android的这种行为没有任何猜测,这样我就可以工作了。我不知道,我必须在我的机器上试试
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));
});