1

画像への絶対パスのリストを取得するメソッドがあります。これらの取得した値を使用して、Windows8アプリケーション内の画像のグリッドを表示したいと思います。注意点は、リストは任意のサイズにすることができるということです。画像が画面いっぱいに表示され、下に続くことを望みます。

これは本当に簡単な質問のように思えますが、Google / Bingを使用してこれを行う方法について明確な答えを見つけることができません。そのため、この場合に誰かが何をすべきかを知っているという偶然の機会に、ここに投稿すると言いました。

現時点では、音楽フォルダからファイルのリストを取得し、それらを画面に表示される文字列に追加しているだけです。画像は表示されず、動的な数の画像でこれをどのように機能させるかわかりません。 。誰かがこれで私を助けることができますか?

これまでのコード:

音楽フォルダ内の画像を取得します:

 private async void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            StorageFolder musicFolder = KnownFolders.MusicLibrary;

            List<string> fileTypeFilter = new List<string>();
            fileTypeFilter.Add(".png");

            QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderBySearchRank, fileTypeFilter);
            //use the user's input to make a query
            queryOptions.UserSearchFilter = InputTextBox.Text;
            StorageFileQueryResult queryResult = musicFolder.CreateFileQueryWithOptions(queryOptions);

            StringBuilder outputText = new StringBuilder();

            //find all files that match the query
            IReadOnlyList<StorageFile> files = await queryResult.GetFilesAsync();
            //output how many files that match the query were found
            if (files.Count == 0)
            {
                outputText.Append("No files found for '" + queryOptions.UserSearchFilter + "'");
            }
            else if (files.Count == 1)
            {
                outputText.Append(files.Count + " file found:\n\n");
            }
            else
            {
                outputText.Append(files.Count + " files found:\n\n");
            }

            //output the name of each file that matches the query
            foreach (StorageFile file in files)
            {
                outputText.Append(file.Name + "\n");
            }

            OutputTextBlock.Text = outputText.ToString();
        }

また、ファイル名は表示されますが画像は表示されないOutputTextBlockのXAML:

<Grid x:Name="Output" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top">
    <TextBlock x:Name="OutputTextBlock" Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap"/>
</Grid>
4

1 に答える 1

1

これがWindows8アプリで機能するかどうかはわかりませんが、WPFでは、次のように試してみます。

<ItemsControl ItemsSource="{Binding Path=YourListOfPaths}" 
              HorizontalContentAlignment="Stretch">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

ItemsSourceItemsControlファイルパスのリスト(eG an ObservableCollection<string>)にバインドされており、ItemTemplate各単一アイテムがどのように表示されるかを説明しています。私Imageは各単一ファイルにコントロールを使用しました。はSourceアイテム自体にバインドされています(これはここでは単一のファイルパスです)。

于 2013-01-08T12:31:38.090 に答える