Click here to Skip to main content
15,891,938 members
Articles / Desktop Programming / WPF

Wrap Panel Virtualization

Rate me:
Please Sign up or sign in to vote.
4.95/5 (18 votes)
2 Jan 2012CPOL2 min read 53.5K   5.6K   41  
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
using System;

namespace MediaAssistant.DAL.Constants
{
    public class LibraryItemType
    {
        public const string IMDbMustWatchList = "IMDbMustWatchList";
        public const string WishListLibrary = "WishListLibrary";
        public const string FailedLibrary = "FailedLibrary";
        public const string StaredMovieLibrary = "StaredMovieLibrary";
        public const string RecommendedMovieLibrary = "RecommendedMovieLibrary";
        public const string UnreadMovieLibrary = "UnreadMovieLibrary";
        public const string RecentlyPlayedMovieLibrary = "RecentlyPlayedMovieLibrary";
        public const string ProcessingLibrary = "ProcessingLibrary";
        public const string Year="Year";
        public const string Rated="Rated";
        public const string Actor="Actor";
        public const string Writer="Writer";
        public const string Director = "Director";
        public const string MovieGenre="Movie Genre";
        public const string RatedLibrary="RatedLibrary";
        public const string WatchListLibrary = "WatchListLibrary";
        public const string YearLibrary = "YearLibrary";
        public const string MovieGenreLibrary = "MovieGenreLibrary";
        public const string WriterLibrary = "WriterLibrary";
        public const string ActorLibrary = "ActorLibrary";
        public const string DirectorLibrary = "DirectorLibrary";
        public const string MovieLibrary = "MovieLibrary";
        public const string NowPlayingPlaylist = "Now Playing";
        public const string LastImportedPlaylist = "Last Imported Music";
        public const string Playlist = "Playlist";
        public const string Genre="Genre";
        public const string Album="Album";
        public const string Artist="Artist";
        public const string GenreLibrary = "GenreLibrary";
        public const string AlbumLibrary = "AlbumLibrary";
        public const string ArtistLibrary = "ArtistLibrary";
        public const string MusicLibrary = "MusicLibrary";
        public const string PlayListLibrary = "PlayListLibrary";
        public const string ComposerLibrary = "ComposerLibrary";
        public const string Composer = "Composer";
        public const int RootItemsCount = 3;
        public static bool IsRootItem(string type)
        {
            switch (type)
            {
                case MovieLibrary:
                case MusicLibrary:
                case PlayListLibrary:
                    return true;
            }
            return false;
        }
        public static bool IsMovieLeaf(string  type)
        {
            switch (type)
            {
                case Actor:
                case Director:
                case Writer:
                case Rated:
                case Year:
                case MovieGenre:
                    return true;
            }
            return false;
        }

        /// <exception cref="Exception">Parent Type not found</exception>
        public static string GetParentType(string type)
        {
            switch (type)
            {
                case Album:
                    return AlbumLibrary;
                case Artist:
                    return ArtistLibrary;
                case Genre:
                    return GenreLibrary;
                case Playlist:
                    return PlayListLibrary;
                case Composer:
                    return ComposerLibrary;

                case AlbumLibrary:
                case ArtistLibrary:
                case GenreLibrary:
                case ComposerLibrary:
                    return MusicLibrary;

                case DirectorLibrary:
                case ActorLibrary:
                case WriterLibrary:
                case MovieGenreLibrary:
                case RatedLibrary:
                case YearLibrary:
                case WatchListLibrary:
                case ProcessingLibrary:
                case FailedLibrary:
                case UnreadMovieLibrary:
                case StaredMovieLibrary:
                case RecommendedMovieLibrary:
                case WishListLibrary:
                case IMDbMustWatchList:
                case RecentlyPlayedMovieLibrary:
                    return MovieLibrary;
                case MovieGenre:
                    return MovieGenreLibrary;
                case Director:
                    return DirectorLibrary;
                case Writer:
                    return WriterLibrary;
                case Actor:
                    return ActorLibrary;
                case Rated:
                    return RatedLibrary;
                case Year:
                    return YearLibrary;
            }
            return String.Empty;
        }

        public static bool IsMusicItem(string type)
        {
            switch (type)
            {
                case Album:
                case Artist:
                case Genre:
                case Playlist:
                case Composer:
                case AlbumLibrary:
                case ArtistLibrary:
                case GenreLibrary:
                case ComposerLibrary:
                case MusicLibrary:
                case PlayListLibrary:
                    return true;
            }
            return false;
        }

        public static bool IsMovieItem(string type)
        {
            switch (type)
            {
                case UnreadMovieLibrary:
                case DirectorLibrary:
                case ActorLibrary:
                case WriterLibrary:
                case MovieGenreLibrary:
                case YearLibrary:
                case RatedLibrary:
                case WatchListLibrary:
                case ProcessingLibrary:
                case FailedLibrary:
                case StaredMovieLibrary:
                case RecommendedMovieLibrary:
                case WishListLibrary:
                case MovieLibrary:
                case MovieGenre:
                case Director:
                case Writer:
                case Actor:
                case Rated:
                case Year:
                case IMDbMustWatchList:
                case RecentlyPlayedMovieLibrary:
                    return true;
            }
            return false;
        }

        public const string MusicType = "Music";
        public const string MovieType = "Movie";

        public static bool CanHaveChildren(string type)
        {
            switch (type)
            {
                case MovieLibrary:
                case DirectorLibrary:
                case ActorLibrary:
                case WriterLibrary:
                case MovieGenreLibrary:
                case YearLibrary:
                case RatedLibrary:

                case MusicLibrary:
                case AlbumLibrary:
                case ArtistLibrary:
                case GenreLibrary:
                case ComposerLibrary:
                case PlayListLibrary:
                    return true;
                default:
                    return false;
            }
        }

        public static bool IsLastParent(string type)
        {
            switch (type)
            {
                case DirectorLibrary:
                case ActorLibrary:
                case WriterLibrary:
                case MovieGenreLibrary:
                case YearLibrary:
                case RatedLibrary:

                case AlbumLibrary:
                case ArtistLibrary:
                case GenreLibrary:
                case ComposerLibrary:
                case PlayListLibrary:
                    return true;
                default:
                    return false;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) KAZ Software Limited
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions