首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

LongListSelector 出现错误。

2013-12-20 
LongListSelector 出现异常。急!异常:{System.ArgumentException: Value does not fall within the expecte

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>


                        </toolkit:ContextMenuService.ContextMenu>
                    </StackPanel>
                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector>


快要发布了,但出现了这个大问题,请大家帮帮忙啊。
[解决办法]
引用:
Quote: 引用:

这是一个BUG,如果你从顶部并且速度很快的删除就会这样,从LongListSelector的底部开始删除就不会

那该如何解决呢?
这个帖子http://social.msdn.microsoft.com/Forums/wpapps/en-US/bec4efbf-269b-4be0-aacc-99c8be59b861/wp8-longlistselector-exception-when-removing-items?forum=wpdevelop
说的是什么解决办法,我看不太懂?


不是给出代码了嘛
public class LongListSelectorEx : LongListSelector
{
    protected override Size MeasureOverride(Size availableSize)
    {
        try
        {
            return base.MeasureOverride(availableSize);
        }
        catch (ArgumentException)
        {
            return base.MeasureOverride(availableSize);
        }
    }
}
继承一下这个类,屏蔽这个异常。
[解决办法]
引用:
Quote: 引用:

Quote: 引用:

这是一个BUG,如果你从顶部并且速度很快的删除就会这样,从LongListSelector的底部开始删除就不会

那该如何解决呢?
这个帖子http://social.msdn.microsoft.com/Forums/wpapps/en-US/bec4efbf-269b-4be0-aacc-99c8be59b861/wp8-longlistselector-exception-when-removing-items?forum=wpdevelop
说的是什么解决办法,我看不太懂?


不是给出代码了嘛
public class LongListSelectorEx : LongListSelector
{
    protected override Size MeasureOverride(Size availableSize)
    {
        try
        {
            return base.MeasureOverride(availableSize);
        }
        catch (ArgumentException)
        {
            return base.MeasureOverride(availableSize);
        }
    }
}
继承一下这个类,屏蔽这个异常。

我之前也用过这个方法,虽然不会崩溃了但是会导致布局错误,目前没有好的办法要么就是换listbox吧

热点排行