0

我目前正在开发一个简单的 Windows 8 应用程序,作为更复杂的概念的准系统证明。

目前,我有一个文本框和两个按钮。一个按钮允许您选择一个文件夹(它会在我的文本框中填充文件夹路径)。

另一个按钮应该返回当前所选文件夹中前 5 张图像的绝对路径,但我在使用FileOpenPickerWin8 应用程序时遇到了一些问题。

我想要做的是,当单击此按钮时,我不想返回图像的前 5 个路径,而是希望以网格格式显示它们,除了向右延伸,更像是向下延伸一个传统的网站。

截屏

到目前为止我所拥有的:

XAML:

<StackPanel Grid.Row="2" Margin="120,0,0,0">
    <StackPanel Orientation="Horizontal" Margin="0,20,0,20">
        <TextBox  x:Name="pictureInput" HorizontalAlignment="Left" Grid.Row="2" TextWrapping="Wrap" Text="Select Image..." VerticalAlignment="Top" Width="300" Height="41" FontSize="24"/>
        <Button Content="Browse" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Height="41" Width="147" Click="Browse_Folder_Click"/>
        <TextBlock x:Name="ImgThumbHere" Grid.Column="2" Width="540"/>
        <Button Content="Find Images" HorizontalAlignment="Left" VerticalAlignment="Top" Height="90"  Width="250" Click="Find_Images"/>
    </StackPanel>
</StackPanel>

Xaml.CS:

//method to select folder : 
     private async void Browse_Folder_Click(object sender, RoutedEventArgs e)
        {
            string folderPath = "";
            FolderPicker folderPicker = new Windows.Storage.Pickers.FolderPicker();
            // Create the picker object and set options
            folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            // Users expect to have a filtered view of their folders depending on the scenario.
            // For example, when choosing a documents folder, restrict the filetypes to documents for your application.
            folderPicker.FileTypeFilter.Add("*");

            StorageFolder folder = await folderPicker.PickSingleFolderAsync();
            if (folder != null)
            {
                if (folder.Path != "" && folder.Path != null)
                {
                    folderPath = folder.Path;
                }
                else
                {
                    folderPath = folder.Name;
                }
            }
            else
            {
                throw new Exception("Folder path null.");
            }
            folderInput.Text = folderPath;
        }

//attempt at method to select first 5 images of selected folder : 

    private async void Find_Images(object sender, RoutedEventArgs e)
        {
            string[] picturePath;
            FileOpenPicker picPicker = new Windows.Storage.Pickers.FileOpenPicker();
            picPicker.ViewMode = PickerViewMode.Thumbnail;
            // Create the picker object and set options
            picPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            // Users expect to have a filtered view of their folders depending on the scenario.
            // For example, when choosing a documents folder, restrict the filetypes to documents for your application.
            picPicker.FileTypeFilter.Add(".png");
            picPicker.FileTypeFilter.Add(".jpg");
            picPicker.FileTypeFilter.Add(".jpeg");
            picPicker.FileTypeFilter.Add(".gif");
            picPicker.FileTypeFilter.Add(".bmp");

            for (int i = 0; i < 5; i++)
            {
                StorageFile file = picPicker.//What can be called here to return paths ?
                if (file != null)
                {
                    picturePath[i] = file.path;
                }
                else
                {
                    throw new Exception("File path null.");
                }
            }
        }

谁能帮我解决这个问题?

非常感谢。

4

1 回答 1

1

看看http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh758319(v=win.10).aspx

问题是,根据设计,您仅限于:

  • 访问本地存储
  • 访问一些著名的存储位置
  • 访问一个特别授权的位置
于 2013-01-07T21:42:18.263 回答