当前位置: 代码迷 >> Windows Mobile >> LongListSelector 出现错误。
  详细解决方案

LongListSelector 出现错误。

热度:101   发布时间:2016-04-25 07:18:55.0
LongListSelector 出现异常。急!
异常:
{System.ArgumentException: Value does not fall within the expected range.}
{System.Collections.ListDictionaryInternal}

这个发生在我逐条删除LongListSelector数据是发生的, MainLongListSelector.ItemsSource 是和ObservableCollection绑定以便动态删除,可是当我每次删除到8,9条时就会发生如上异常。

 我的xmal:
<phone:LongListSelector x:Name="MainLongListSelector" Margin="0,0,-12,0" ItemsSource="{Binding DuplicateContacts}">
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Grid>                
                            <TextBlock Text="{Binding DisplayName}" 
                                   Foreground="Black" 
                                   TextTrimming="WordEllipsis"
                                   Margin="30,10,50,10"
                                   VerticalAlignment="Center"
                                   Style="{StaticResource PhoneTextLargeStyle}"/>
                            <Button x:Name="Detail" 
                                HorizontalAlignment="Right" BorderThickness="0"
                                VerticalAlignment="Bottom"
                                Margin="0,10,20,10"
                                Click="Detail_Click">
                                <Button.Background>
                                    <ImageBrush Stretch="Uniform" ImageSource="/Images/rightwards.png"/>
                                </Button.Background>
                            </Button>
                        </Grid>
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu IsZoomEnabled="True">
                                <toolkit:MenuItem Header="Delete" CommandParameter="{Binding}"
                                                      Click="MenuItem_Click"/>
                            </toolkit:ContextMenu>