The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Unable to show folders inside a WrapGrid in WP 8.1? RRS feed

  • Question

  • I new to WP 8.1. I am trying to show Music Folders from a Windows Phone 8.1 inside WrapGrid. I am able to access the Folders but I am unable to display them as Folders in the XAML design I have built.

    Here's my XAML Code:

    <Button x:Name="dumybutton" Content="Click me to see Folders" Background="#FF6E5FCF" Click="dumyclick"/>
                        <Grid x:Name="ShowFolders" Background="#FFEA8282">
                            <ScrollViewer>
                                <ListView x:Name="ViewMusicFolders" Grid.Row="1" Grid.Column="2" VirtualizingStackPanel.VirtualizationMode="Recycling" SelectionMode="None" IsActiveView="True">                                    
                                    <ListView.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="2" />
                                        </ItemsPanelTemplate>
                                    </ListView.ItemsPanel>
                                </ListView>
                            </ScrollViewer>
             </Grid>


    My C# code:

    private void dumyclick(object sender, TappedRoutedEventArgs e)
    {
      ViewMusicFolders.Opacity = 1;
      GenerateFolders();
    }
    
    private async void GenerateFolders()
            {
                try
                {
                    // To get all music folders
                    IReadOnlyList<IStorageItem> MusicFolders = await KnownFolders.MusicLibrary.GetFoldersAsync();                
                    SeeFolders(MusicFolders);
                }
                catch
                {
    
                }
                finally
                {
    
                }
            }
    
    private async void SeeFolders(IReadOnlyList<IStorageItem> MusicFolderList)
            {
                try
                {
    
                   foreach(IStorageItem mItem in MusicFolderList)
                   {
                       IStorageItem item = mItem;
                       int temp = 0;
    
                       // Checks if the item is a Folder
                       if(item.IsOfType(Windows.Storage.StorageItemTypes.Folder))
                       {                       
                           StorageFolder mFolder = (StorageFolder)item;
    
                           // To get all Items (Files & Folders) present in the folder
                           IReadOnlyList<IStorageItem> fileList = await mFolder.GetItemsAsync();
    
                           // checks the count. If folder contains any files or sub-folders, fetch details & then traverse through the fileList.
                           if(fileList.Count >0)
                           {
                               // create object of MusicAlbums() class.
                               MusicF musicAlbumObj = new MusicAlbums();
    
                               // set name of item Folder.
                               musicAlbumObj.strName = item.Name;
    
                               // set path of item Folder.
                               musicAlbumObj.strPath = item.Path;
    
    
                               string showText = "";
                               showText = musicAlbumObj.strName + " *** " + musicAlbumObj.strPath;
                               MessageDialog msg = new MessageDialog(showText);
                               await msg.ShowAsync(); 
                           }                      
                       }                 
                       }
                   }
                }
                catch
                {
    
                }
                finally
                {
    
                }
    
            }

    My MusicF Class

     public class MusicF
        {
            public string strName { get; set; }
            public string strPath { get; set; }
        }



    • Edited by Nameless777 Monday, November 24, 2014 11:36 AM
    Monday, November 24, 2014 7:08 AM

Answers

All replies

  • You only have defined the ItemsPanelTemplate, but havn't defined ItemsTemplate.

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Monday, November 24, 2014 12:45 PM
  • Yes, like Bill said.

    You didn't implement any itempanletemplate, check this tutorial will help you understand how to design it:

    http://blogs.msdn.com/b/mim/archive/2013/04/16/winrt-create-a-custom-itemspanel-for-an-itemscontrol.aspx

    • Marked as answer by Nameless777 Thursday, November 27, 2014 5:26 AM
    Tuesday, November 25, 2014 2:54 AM