Click here to Skip to main content
15,886,067 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.2K   5.6K   41  
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Tags.Objects
{
    /// <summary>
    /// Provide an object to read and write unknown objects of ASF
    /// </summary>
    public class GeneralObject : ASFObject
    {
        byte[] _Data;
        string _GUID;

        /// <summary>
        /// Create new GeneralObject from specific TagStream
        /// </summary>
        /// <param name="rd">TagStream to read data from</param>
        /// <param name="ObjectSize">Object size to read from TagStream</param>
        /// <param name="GUID">GUID of object</param>
        public GeneralObject(TagStream rd, long ObjectSize, string GUID)
        {
            Read(rd, ObjectSize);
            _GUID = GUID;
        }

        /// <summary>
        /// Read data from specific TagStream
        /// </summary>
        /// <param name="rd">TagStream to read data from</param>
        /// <param name="ObjectSize">Object size in tag stream</param>
        /// <returns>true if readed successfully otherwise false</returns>
        protected override bool OnReadingData(TagStream rd, long ObjectSize)
        {
            _Data = new byte[ObjectSize];
            rd.Read(_Data, 0, (int)ObjectSize);
            return true;
        }

        /// <summary>
        /// Call when frame need to write it's data to stream
        /// </summary>
        /// <param name="wr">TagStream to write data</param>
        protected override bool OnWritingData(TagStream wr)
        {
            wr.WriteGUID(this.GUID);
            wr.AsBinaryWriter.Write((long)Length);

            wr.Write(_Data, 0, _Data.Length);
            return true;
        }

         /// <summary>
        /// Gets length of current frame in byte
        /// </summary>
        /// <returns>int contain length of current frame</returns>
        protected override long OnGetLength()
        {
            return _Data.Length + 24;
        }

        /// <summary>
        /// Gets GUID of current object
        /// </summary>
        /// <returns>String contain GUID of current object</returns>
        protected override string OnGetGUID()
        {
            return _GUID;
        }
    }
}

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