/// <summary>
        /// Create a gallery item to represent a file.
        /// This method may return null if it decides to not include this file.
        /// </summary>
        private ThumbnailCommand CreateFileGalleryItem(IModelItemOwner owner, FileInfo info)
        {
            // Only list WMA and MP3 file types
            string extension = FilterExtension(info.Extension);

            if ((extension != "wma") && (extension != "mp3"))
            {
                return(null);
            }

            // Create the command
            ThumbnailCommand item = new ThumbnailCommand(owner);

            item.Description  = info.Name;
            item.Metadata     = extension;
            item.Image        = fileImage;
            item.Data["Path"] = info.FullName;

            // Hook up the invoked handler
            item.Invoked += delegate(object sender, EventArgs args)
            {
                ThumbnailCommand invokedFile = (ThumbnailCommand)sender;
                string           path        = (string)invokedFile.Data["Path"];

                //
                // When invoked play the audio file
                //

                if (Application.Current.MediaCenterEnvironment != null)
                {
                    // Play
                    Application.Current.MediaCenterEnvironment.PlayMedia(MediaType.Audio, path, true);

                    // Display a notification that will time out.
                    Application.Current.MessageBox(Z.Resources.Music_PlayDialog_Text, invokedFile.Description, 4, false);
                }
                else
                {
                    Debug.WriteLine("Play " + path);
                }
            };

            return(item);
        }
        /// <summary>
        /// Create a gallery item to represent a directory.
        /// </summary>
        private ThumbnailCommand CreateDirectoryGalleryItem(IModelItemOwner owner, DirectoryInfo info)
        {
            // Create the command
            ThumbnailCommand item = new ThumbnailCommand(owner);

            item.Description  = info.Name;
            item.Image        = directoryImage;
            item.Data["Path"] = info.FullName;

            // Hook up the invoked handler
            item.Invoked += delegate(object sender, EventArgs args)
            {
                ThumbnailCommand invokedDirectory = (ThumbnailCommand)sender;
                string           path             = (string)invokedDirectory.Data["Path"];

                // When invoked navigate to a new gallery page for this directory
                GalleryPage newPage = CreateGalleryPage(path);
                Application.Current.GoToGallery(newPage);
            };

            return(item);
        }
        /// <summary>
        /// Create gallery items for all the subdirectories and music files found in the given directory.
        /// </summary>
        private void PopulateGallery(IModelItemOwner owner, IList list, DirectoryInfo directory)
        {
            //
            // Subdirectories
            //

            DirectoryInfo[] subdirectories = directory.GetDirectories();

            if (subdirectories != null)
            {
                foreach (DirectoryInfo subdirectory in subdirectories)
                {
                    ThumbnailCommand item = CreateDirectoryGalleryItem(owner, subdirectory);
                    if (item != null)
                    {
                        list.Add(item);
                    }
                }
            }


            //
            // Files
            //

            FileInfo[] files = directory.GetFiles();

            if (files != null)
            {
                foreach (FileInfo file in files)
                {
                    ThumbnailCommand item = CreateFileGalleryItem(owner, file);
                    if (item != null)
                    {
                        list.Add(item);
                    }
                }
            }
        }
        /// <summary>
        /// Finishes any slow data for a gallery item.
        /// </summary>
        private void CompleteGalleryItem(VirtualList list, int index)
        {
            ThumbnailCommand item = (ThumbnailCommand)list[index];

            // This is where we would load a thumbnail for this item.
        }