我使用ObservableCollection<BarcodeInfo>
作为ItemsSource
的ListView
生成ViewCells
。一个细胞包含2 Labels
和一个ZXingBarcodeImageView
与我的BarcodeInfo
-class绑定,一切都按预期工作。ZXingBarcodeImageView从ObservableCollection移除时出现异常
现在我已经从ListView
删除多个细胞,但只要我尝试这样做,我从ZXingBarcodeImageView
System.ArgumentException以下异常:发现空的内容
这里是我的XAML
<ListView RowHeight="50">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<zxing:ZXingBarcodeImageView
BarcodeFormat="{Binding Format}"
BarcodeOptions="{Binding Options}"
BarcodeValue="{Binding Text}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Margin="5"
Grid.Column="0"/>
<StackLayout Grid.Row="0" Grid.Column="1"
Spacing="0" VerticalOptions="CenterAndExpand">
<Label Text="{Binding Text}"
LineBreakMode="TailTruncation"
VerticalOptions="End"/>
<Label Text="{Binding Format}"
VerticalOptions="End"
LineBreakMode="TailTruncation"/>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
而在该ListVi的班ObservableCollection<BarcodeInfo> _barcodeCollection;
EW
public class BarcodeInfo
{
public string Text
{ get; set; }
public string Detail
{ get; set; }
public BarcodeFormat Format
{ get; set; }
public EncodingOptions Options
{ get; set; }
}
例外,一旦发生,因为我尝试
_barcodeCollection.RemoveAt(i);
我已经实现了INotifyPropertyChanged
,并试图将所有属性设置为null这无一例外的作品,但ZXingBarcodeImageView不清除条形码-Image和异常仍然抛出,如果我尝试从集合中删除该项目。我处于一个没有更多想法的地步。
我希望有人能帮助我。
更新 因为i
似乎在这里混淆年代环路我使用它
for (int i = 0; i < _barcodeCollection.Count; i++)
{
var response =
await _serverUrl.PostUrlEncodedAsync(
new { barcode = _barcodeCollection[i].Text })
.ReceiveString();
if (string.Equals(response, "ok", StringComparison.OrdinalIgnoreCase))
{
percentage += progressSteps;
_barcodeCollection.RemoveAt(i); //EXCEPTION!!!
i--; // index must be checked twice else one element will be skipped
await UploadProgress.ProgressTo(percentage, 250, Easing.Linear);
}
}
你的“我”是什么?当你删除了所有的元素,并且你仍然试图从集合中删除某些东西时,情况并非如此。 –
'i'是for循环的一部分for(int i = 0; i <_barcodeCollection.Count; i ++)'里面是我检查的东西,如果是的话我试着去掉元素 –
不要''' RemoveAt移除(ⅰ)'。 – Clemens