Click here to Skip to main content
15,892,768 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.6K   5.6K   41  
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
using System;
using System.IO;
using System.Linq;

namespace MediaAssistant.DAL
{
    public class Utility
    {
        public static string GetFileSize(long length)
        {
            string fileSize = length + " Bytes";
            double dlength = length;
            if (dlength >= 1024)
            {
                dlength = dlength / 1024;
                fileSize = String.Format("{0:#,0.##} KB", dlength);
            }
            if (dlength >= 1024)
            {
                dlength = dlength / 1024;
                fileSize = String.Format("{0:#,0.##} MB", dlength);
            }
            if (dlength >= 1024)
            {
                dlength = dlength / 1024;
                fileSize = String.Format("{0:#,0.##} GB", dlength);
            }
            return fileSize;
        }

        public static bool IsMusicFile(string fileName)
        {
            var extension = Path.GetExtension(fileName);
            return String.Compare(extension, ".mp3", true)==0 || String.Compare(extension, ".wma", true)==0;
        }

        public static bool IsMovieFile(string fileName)
        {
            var extension = Path.GetExtension(fileName);
            return SupportedMovieFileExtension.Any(se => String.Compare(extension, se) == 0);
        }

        public const int HundredMB = 104857600;
        public const int MinMovieFileSize = HundredMB;
        private static readonly string [] _supportedMovieFileExtension=new[]{".avi",".mkv",".flv",".mp4",".wmv"};
        public const string SupportedFileFilter = "Music Files (*.mp3, *.wma)|*.mp3;*.wma|Movie Files (*.avi,*.mkv,*.flv,*.mp4,*.wmv)|*.avi;*.mkv;*.flv;*.mp4;*.wmv";
        public const string SupportedMovieFileFilter = "Movie Files (*.avi,*.mkv,*.flv,*.mp4,*.wmv)|*.avi;*.mkv;*.flv;*.mp4;*.wmv";

        public static bool IsSupportedMovieFile(string fileName)
        {
            var extension = Path.GetExtension(fileName);
            return SupportedMovieFileExtension.Any(e => String.Compare(e, extension, true) == 0);
        }

        public static int GetSupportedMovieCount(string fullPath)
        {
            return SupportedMovieFileExtension.Sum(supportedExtension => GetFileCount(fullPath, supportedExtension, MinMovieFileSize));
        }

        private static int GetFileCount(string fullPath, string extension, int minFileSize)
        {
            return Directory.GetFiles(fullPath, String.Format("*{0}", extension)).Where(f => new FileInfo(f).Length > minFileSize).Count();
        }

        public static string[] SupportedMovieFileExtension
        {
            get { return _supportedMovieFileExtension; }
        }

        
    }
}

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