将图像添加到gridview windows 8商店应用程序时出错

时间:2013-06-23 21:25:30

标签: c# xaml gridview windows-store-apps

我正在尝试将我从网络摄像头获取的图像添加到gridview,但每次我都会遇到异常。我有单独的页面从网络摄像头制作图片后来,我将图像完整路径传递到其他页面。以下是代码段:

C#

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    //If navigated from PhotoCapturePage
    if (m_ToBeNavigatedPageType == typeof(PhotoCapturePage))
    {
        if (e.Parameter == null)
        {
            return;
        }
        Image img = new Image();
        img.Width = 64;
        img.Height = 64;
        img.Source = new BitmapImage(new Uri(e.Parameter.ToString()));

        IncidentPictures.Add(img);

        IncidentPictureGrid.Items.Add(img);
    }
}

XAML:

<GridView ItemsSource="{Binding IncidentPictures}" Name="IncidentPictureGrid" Width="350"></GridView>

每次执行IncidentPictureGrid.Items.Add(img)时,我都会收到灾难性失败(Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))例外情况。 有人有建议吗?

提前致谢, Miroslawas

1 个答案:

答案 0 :(得分:0)

为什么在将图像添加到IncidentPictures集合时也将图像添加到Grid.Items集合中?

您已将GridView的ItemsSource绑定到集合。也许这会导致错误...删除IncidentPictureGrid.Items.Add并确保,IncidentPictures是一个ObservableCollection。