0
我正在研究一個簡單的Windows 8應用程序,作爲一個更復雜的事情的準系統證明。在Windows 8應用程序中顯示動態圖片gallerys?
此刻,我有一個文本框和兩個按鈕。一個按鈕允許您選擇一個文件夾(在我的文本框中填充文件夾路徑)。
另一個按鈕應該返回當前選定文件夾中前5個圖像的絕對路徑,但我在Win8應用程序中使用FileOpenPicker
時遇到了一些問題。
我想要做的是,當點擊此按鈕而不是返回圖像的前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.");
}
}
}
誰能幫我來解決這一問題?
非常感謝。