C# 如何将Gridview控件连接到StorageFolder

C# 如何将Gridview控件连接到StorageFolder,c#,windows-store-apps,C#,Windows Store Apps,我正在进行一项任务,制作一个文件浏览器应用程序,您可以在其中查看选定文件夹中的所有文件/文件夹列表,并可以打开这些文件夹。我使用folderpicker类从系统中拾取文件或文件夹,但无法在Gridview中打开选定的文件。我附上此任务的代码图像 private async void Button_Click(object sender, RoutedEventArgs e) { fp.SuggestedStartLocation = PickerLocationId.D

我正在进行一项任务,制作一个文件浏览器应用程序,您可以在其中查看选定文件夹中的所有文件/文件夹列表,并可以打开这些文件夹。我使用folderpicker类从系统中拾取文件或文件夹,但无法在Gridview中打开选定的文件。我附上此任务的代码图像

 private async void Button_Click(object sender, RoutedEventArgs e)
    {
        fp.SuggestedStartLocation = PickerLocationId.Desktop;
        fp.ViewMode = PickerViewMode.Thumbnail;
        fp.FileTypeFilter.Add("*");
        StorageFolder sf = await fp.PickSingleFolderAsync();

        if (sf != null)
        {

            IReadOnlyList<IStorageItem> read = await sf.GetItemsAsync();
            g.ItemsSource = read;
            g.DisplayMemberPath = "name";
           // g.CompleteViewChange();


        }
    }
private async void按钮\u单击(对象发送方,路由目标)
{
fp.SuggestedStartLocation=PickerLocationId.Desktop;
fp.ViewMode=PickerViewMode.Thumbnail;
fp.FileTypeFilter.Add(“*”);
StorageFolder sf=wait fp.PickSingleFolderAsync();
如果(sf!=null)
{
IReadOnlyList read=wait sf.GetItemsAsync();
g、 ItemsSource=读取;
g、 DisplayMemberPath=“name”;
//g.完成视图更改();
}
}

您可以通过将数据绑定到GridView来实现这一点

参考此


浏览用于将UI绑定到控件的界面

建议将代码粘贴在此处,而不要链接。这样人们就可以尝试你的代码。我现在发布了代码。请仔细检查一下。你打开文件的目的是什么。我甚至看不到IStorageItem.Path属性的用法。我不熟悉编码,不了解绑定概念。我尝试了使用数据绑定概念,但我只能访问选定文件夹中选定的一个文件