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 {}
}
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 MusicF();
// 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 {}
}
My MusicF Class
public class MusicF
{
public string strName { get; set; }
public string strPath { get; set; }
}