【问题标题】:System.Exception when clearing items in Flipview在 Flipview 中清除项目时出现 System.Exception
【发布时间】:2014-02-19 09:03:47
【问题描述】:

所以我试图使用Items.Clear() 在翻转视图中清除我的项目。但是在尝试清除项目时,错误总是显示“System.Exception”。这是我的代码:

        openPicker.FileTypeFilter.Clear();
        openPicker.FileTypeFilter.Add(".bmp");
        openPicker.FileTypeFilter.Add(".png");
        openPicker.FileTypeFilter.Add(".jpeg");
        openPicker.FileTypeFilter.Add(".jpg");
        var files = await openPicker.PickMultipleFilesAsync();


        if (files != null)

        {
            //foreach (StorageFile Images in files)
            foreach (var file in files)
            {
            Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
              //Some imagedecoder here
               BitmapImage img = new BitmapImage();
                    img.SetSource(outStream);
              }


            }
         flpcakeimages.Items.Clear(); //System.Exception error here it says'Catastrophic error'
         flpCakeImages.ItemsSource = images;

这是更新翻转视图的正确方法吗?我用了.UpdateLayout,但还是不行,请大家帮帮我好吗?

【问题讨论】:

    标签: c# windows windows-runtime microsoft-metro


    【解决方案1】:

    你可以替换

    flpcakeimages.Items.Clear();
    

    flpCakeImages.ItemsSource = null;
    

    如果您无法替换flipView的内容,请这样做:

    flpCakeImages.ItemsSource = oldDataSource;
    flpCakeImages.ItemsSource = null;
    flpCakeImages.ItemsSource = newDataSource;
    

    【讨论】:

    • 谢谢!它回答了我的一半问题,它很好地更新了我的翻转视图,现在问题是,我想清除翻转视图的内容并替换它的内容。我该怎么做?
    • 或者你可以尝试替换你的数据源。但您的数据源必须是 ObservableCollection。
    • 现在我的代码错误,当我尝试导航到我的图片时它返回到第一张图片为什么会发生这种情况?
    • 导航到您的图片是什么意思?您可以设置翻转视图的选定索引。
    • 我的意思是翻阅翻转视图。但非常感谢你帮助我! :) 我已经稍微调整了我的代码,现在它正在替换和更新我的翻转视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    相关资源
    最近更新 更多