<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Eternal Coding</title><subtitle type="html">var life = new[] {&amp;quot;eat&amp;quot;, &amp;quot;sleep&amp;quot;, &amp;quot;code&amp;quot;}</subtitle><id>http://blogs.msdn.com/b/eternalcoding/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/eternalcoding/atom.aspx" /><generator uri="http://telligent.com" version="5.6.50428.7875">Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><updated>2013-02-28T05:54:00Z</updated><entry><title>Using Visual Studio’s Javascript Memory Analysis tool to find memory leaks on your Windows 8 Javascript app</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/24/using-visual-studio-s-javascript-memory-analysis-tool-to-find-memory-leaks-on-your-windows-8-javascript-app.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/24/using-visual-studio-s-javascript-memory-analysis-tool-to-find-memory-leaks-on-your-windows-8-javascript-app.aspx</id><published>2013-04-24T08:24:28Z</published><updated>2013-04-24T08:24:28Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;Javascript&lt;/strong&gt; is a wonderful language for developing Windows 8 apps. As a untyped, dynamic language, &lt;strong&gt;Javascript&lt;/strong&gt; is really flexible but sometimes if you are not careful you may leave some memory leaks in your code.&lt;/p&gt;  &lt;p&gt;But do not worry, &lt;strong&gt;Visual Studio&lt;/strong&gt; includes a great tool called &lt;strong&gt;Javascript Memory Analysis&lt;/strong&gt; in order to help you find out where the leaks are.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8204.image_5F00_32004984.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4643.image_5F00_thumb_5F00_2AE39DBD.png" width="722" height="415" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Using the Javascript Memory Analysis tool&lt;/h1&gt;  &lt;p&gt;This tool is available in the &lt;strong&gt;Debug&lt;/strong&gt; menu of your &lt;strong&gt;Visual Studio&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8787.image_5F00_55BE9280.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2818.image_5F00_thumb_5F00_057C3B00.png" width="868" height="186" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Launching the tool will launch your app and will show this screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1325.image_5F00_2048610C.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3808.image_5F00_thumb_5F00_5006098B.png" width="948" height="606" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The first part of the window is dedicated to the real-time monitoring of the memory used by the application:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8272.image_5F00_18BF8250.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6622.image_5F00_thumb_5F00_14490189.png" width="678" height="120" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Right after you can find a button (&lt;em&gt;Take Heap Snapshot&lt;/em&gt;) used to capture the instantaneous state of the memory heap (The control also indicates the size of the heap and the number of active objects):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0456.image_5F00_4CF3AB96.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6523.image_5F00_thumb_5F00_53A945CA.png" width="1056" height="680" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;By clicking on the heap size, a more detailed view is generated:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/7128.image_5F00_3C119857.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5732.image_5F00_thumb_5F00_2B99275C.png" width="864" height="575" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This view presents a sorted list of the objects by retained size, &lt;strong&gt;which means the objects consuming the most memory that are potentially easiest to free would be listed first.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For instance, in my app, I can see that the &lt;em&gt;UrzaGatherer&lt;/em&gt; object retains almost &lt;strong&gt;60 MB&lt;/strong&gt; (which is normal because it handles a huge list of &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/20/how-to-cook-a-windows-8-application-with-html5-javascrip-css3-rtm-version.aspx"&gt;cards&lt;/a&gt;):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5224.image_5F00_301238D4.png"&gt;&lt;img title="image" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0434.image_5F00_thumb_5F00_3895981E.png" width="1022" height="579" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The view can also display:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;a list of types sorted by occurrence count &lt;/li&gt;    &lt;li&gt;a list of root objects (from the garbage collector point of view)&lt;/li&gt;    &lt;li&gt;a list of &lt;strong&gt;DOM&lt;/strong&gt; objects sorted by retained size&lt;/li&gt;    &lt;li&gt;a list of &lt;strong&gt;WinRT&lt;/strong&gt; objects sorted by retained size&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;   &lt;br /&gt;All of these views can potentially help you find &lt;strong&gt;inconsistent&lt;/strong&gt; memory usage.&lt;/p&gt;  &lt;h1&gt;Comparing snapshots&lt;/h1&gt;  &lt;p&gt;Each time you click on &lt;em&gt;Take Heap Snapshot &lt;/em&gt;button, the system generates a new dump of the heap for further analysis. Furthermore, each snapshot indicates the difference of the heap size and objects count against previous snapshot.&lt;/p&gt;  &lt;p&gt;This is the &lt;strong&gt;key&lt;/strong&gt; for finding memory leaks.&lt;/p&gt;  &lt;p&gt;For instance, in my app, I will take a first snapshot, navigate to a given page, then go back to home page and finally take a second snapshot. Doing this I will be able to see if the given page produces memory leaks.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2313.image_5F00_3D0EA996.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0841.image_5F00_thumb_5F00_411B8819.png" width="664" height="325" /&gt;&lt;/a&gt;&lt;/p&gt;  We can see here that between the two snapshots, the heap size has grown of &lt;strong&gt;6.12 MB&lt;/strong&gt; and more than &lt;strong&gt;53k &lt;/strong&gt;objects were generated and still alive.&amp;#160;&amp;#160; &lt;p&gt;By clicking on the heap size difference (+6.12 MB), you can view a detail of the heap size compared to previous snapshot:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6523.image_5F00_16CEE0EF.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5633.image_5F00_thumb_5F00_0892F8B0.png" width="1024" height="293" /&gt;&lt;/a&gt;    &lt;br /&gt;The Dominators view indicates that new objects remain when we come back to the home page. You can use this view to identify unwanted objects.&lt;/p&gt;  &lt;p&gt;In my case, the first line seems suspicious. By right-clicking on it, I can go to the Root view to see which function retains my objects:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8666.image_5F00_485F6FE6.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4137.image_5F00_thumb_5F00_60F19DE7.png" width="1024" height="415" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; We can see that the object is retained by a function called &lt;em&gt;ImportFromTappedOut&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;After looking for this function in my code, it turns out that this function is a global function which takes a&amp;#160; function as parameter:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;I&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;mportFromTappedOut = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(deckName, &lt;strong&gt;&lt;u&gt;custom&lt;/u&gt;&lt;/strong&gt;) {&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;em&gt;custom &lt;/em&gt;parameter is used by this function to call some specific user code. The main problem is that because the &lt;em&gt;ImportFromTappedOut&lt;/em&gt; is a global function it will retain all the code referenced by the function affected to the &lt;em&gt;custom&lt;/em&gt; parameter and in my case I used an anonymous function that references a lot of local DOM objects:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt; Tools.ImportFromTappedOut(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
     &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;select = document.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#addToDeck&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
     &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;count = document.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#addToDeckCount&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).value;

     listView.selection.getItems().then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(items) {
         appBar.hide();
         appBar.sticky = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
         listView.selection.clear();&lt;br /&gt;&lt;em&gt;…code continue…&lt;/em&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And this exactly the problem described by the tool:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5633.image_5F00_1DA92678.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0743.image_5F00_thumb_5F00_222237F0.png" width="647" height="125" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The solution is easy: I just have to call &lt;em&gt;importFromTappedOut&lt;/em&gt; with a null function when I leave the page in order to allow the garbage collector to collect all retained objects (1.25 MB here).&lt;/p&gt;

&lt;p&gt;I clearly encourage you to use this tool to detect and eradicate memory leaks. It is simple and really powerful and can help you get rid of memory problems.&lt;/p&gt;

&lt;h1&gt;More about the tool&lt;/h1&gt;

&lt;p&gt;Others articles you may find useful:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/visualstudio/archive/2013/02/04/10388914.aspx"&gt;JavaScript memory analysis for Windows Store apps in Visual Studio 2012&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/11/15/optimizing-javascript-windows-8-application-using-the-visual-studio-performance-analysis-tool-profiler.aspx"&gt;Optimizing JavaScript Windows 8 application: Using the Visual Studio performance analysis tool (profiler)&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/20/how-to-cook-a-windows-8-application-with-html5-javascrip-css3-rtm-version.aspx"&gt;How to cook a Windows 8 application with HTML5/Javascript/CSS3&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx"&gt;Unleash the power of HTML 5 Canvas for gaming&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;[French]&lt;a title="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=f721312a-cc92-4599-8795-cfe07d5c0bb4" href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=f721312a-cc92-4599-8795-cfe07d5c0bb4"&gt;http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=f721312a-cc92-4599-8795-cfe07d5c0bb4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10413587" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="HTML5" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML5/" /><category term="HTML 5" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML+5/" /><category term="Javascript" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/" /><category term="CSS3" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/CSS3/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/" /><category term="WinRT" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/" /><category term="Visual Studio" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Visual+Studio/" /></entry><entry><title>Now with Javascript: Reading PDF and XPS on your Windows 8 application using WinRT</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/22/now-with-javascript-reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/22/now-with-javascript-reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx</id><published>2013-04-22T07:10:54Z</published><updated>2013-04-22T07:10:54Z</updated><content type="html">&lt;p&gt;Following my previous article on “&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/15/reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx"&gt;Reading PDF and XPS on your Windows 8 application using WinRT&lt;/a&gt;”, I would like to share with you the same example but with &lt;strong&gt;Javascript&lt;/strong&gt; code.&lt;/p&gt;  &lt;!--more--&gt;    &lt;p&gt;Many of you sent me a mail to get this code, so feel free to grab it here (&lt;em&gt;I would like to thank Mehdi Lahlou for his original version&lt;/em&gt;):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.catuhe.com/msdn/js.PDFReader.zip"&gt;http://www.catuhe.com/msdn/js.PDFReader.zip&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The principle is the &lt;strong&gt;same&lt;/strong&gt; as for C#: I use a &lt;em&gt;FlipView&lt;/em&gt; control that uses a custom template to generate.&lt;/p&gt;  &lt;p&gt;The &lt;em&gt;FlipView&lt;/em&gt; is nothing but a standard &lt;em&gt;WinJS&lt;/em&gt; control:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.UI.FlipView&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;flipView&amp;quot;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To open the PDF file, we can use the following code (standard &lt;em&gt;WinRT&lt;/em&gt; code):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;openPDF: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(filename) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(filename).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(file) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage.FileIO.readBufferAsync(file).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(fileBuffer) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;MuPDFWinRT.Document.create(fileBuffer, MuPDFWinRT.DocumentType.pdf, &lt;br /&gt;                               Windows.Graphics.Display.DisplayProperties.logicalDpi);
        });
    });
},&lt;/span&gt;&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;p&gt;Please note that the MuPDFWinRT component used here is strictly the same as the one used by C#&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once the PDF is opened we can configure the &lt;em&gt;FlipView&lt;/em&gt; using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.openPDF(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;test.pdf&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(pdfDocument) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;array = [];
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; pdfDocument.pageCount; i++) {
        array.push(i);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;dataList = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;WinJS.Binding.List(array);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;flipViewDOM = document.getElementById(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;flipView&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;flipView = flipViewDOM.winControl;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width = flipViewDOM.clientWidth;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height = flipViewDOM.clientHeight;
    
    flipView.itemDataSource = dataList.dataSource;
    flipView.itemTemplate = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(itemPromise) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;itemPromise.then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(item) {
            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// root element for the item
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvas = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;canvas&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            
            canvas.style.width = width;
            canvas.style.height = height;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvasContext = canvas.getContext(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            that.drawPage(pdfDocument, canvasContext, item.index);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvas;
        });
    });
});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Each page will be generated using a canvas stretched to fill the &lt;em&gt;FlipView&lt;/em&gt;. Each canvas is then filled using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;drawPage: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(pdfDocument, canvasContext, index) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;size = pdfDocument.getPageSize(index);

    canvasContext.canvas.width = size.x;
    canvasContext.canvas.height = size.y;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData = canvasContext.createImageData(size.x, size.y);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Int32Array(size.x * size.y);

    pdfDocument.drawPage(index, current, 0, 0, size.x, size.y, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// from  ARGB to ABGR
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; current.length; i++) {

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;val = current[i];

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cursor = i * 4;

        imageData.data[cursor] = (val &amp;gt;&amp;gt; 16) &amp;amp; 0xFF; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;//r
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData.data[cursor + 1] = (val &amp;gt;&amp;gt; 8) &amp;amp; 0xFF; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;//g
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData.data[cursor + 2] = val &amp;amp; 0xFF; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;//b
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData.data[cursor + 3] = 255; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// a
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}            
    canvasContext.putImageData(imageData, 0, 0);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Using &lt;em&gt;pdfDocument.drawPage&lt;/em&gt;, you can fill the image data object created by the canvas. You must then invert pixel color components to switch from ARGB to ABGR and finally paste the result Inside the canvas.&lt;/p&gt;

&lt;p&gt;And voila! &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10412951" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="Javascript" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/" /><category term="PDF" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/PDF/" /></entry><entry><title>Reading PDF and XPS on your Windows 8 application using WinRT</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/15/reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/15/reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx</id><published>2013-04-15T09:20:40Z</published><updated>2013-04-15T09:20:40Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt; and &lt;strong&gt;XPS&lt;/strong&gt; file formats are widely used across the world and you could need one day to display them inside your &lt;img style="float: right; display: inline;" align="right" src="http://ts4.mm.bing.net/th?id=H.4786059119429635&amp;amp;pid=1.7&amp;amp;w=180&amp;amp;h=176&amp;amp;c=7&amp;amp;rs=1" width="94" height="92" /&gt;application.&lt;/p&gt;  &lt;p&gt;Today I would like to share with you a simple way to do so by using an open source solution: &lt;a href="http://mupdf.com/"&gt;&lt;strong&gt;MuPDF&lt;/strong&gt;&lt;/a&gt; (a multiplatform lightweight PDF and XPS viewer).&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;MuPDF&lt;/strong&gt; is already working on a &lt;strong&gt;WinRT&lt;/strong&gt; solution you can grab on this GIT repo: &lt;a title="http://git.ghostscript.com/?p=user/mvrhel/mupdf.git;a=summary" href="http://git.ghostscript.com/?p=user/mvrhel/mupdf.git;a=summary"&gt;http://git.ghostscript.com/?p=user/mvrhel/mupdf.git;a=summary&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;I also used the work of &lt;strong&gt;&lt;a href="https://github.com/libreliodev/windows8"&gt;Libreliodev&lt;/a&gt;&lt;/strong&gt; and especially their advanced port of &lt;strong&gt;MuPDF&lt;/strong&gt; for &lt;strong&gt;WinRT&lt;/strong&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The result is a simple but really useful &lt;em&gt;Windows 8 Modern UI&lt;/em&gt; app that is able to display a &lt;strong&gt;PDF&lt;/strong&gt;/&lt;strong&gt;XPS&lt;/strong&gt; file: &lt;a href="http://www.catuhe.com/msdn/pdfreader.zip"&gt;http://www.catuhe.com/msdn/pdfreader.zip&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/pdfreader2.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/pdfreader2.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;  &lt;!--more--&gt;  &lt;p&gt;The solution is based on two projects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;MuPDF.winRT&lt;/strong&gt;: a C++/CX &lt;strong&gt;WinRT&lt;/strong&gt; component built upon &lt;strong&gt;MuPDF&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;PDFReader&lt;/strong&gt;: A C#XAML project that used the &lt;strong&gt;WinRT&lt;/strong&gt; component to display a &lt;strong&gt;PDF&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;For this article I created a C#/XAML application. But because MuPDF.winRT is a WinRT component, you can also use it from a &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/22/now-with-javascript-reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx"&gt;HTML5/CSS3/Javascript app&lt;/a&gt;!&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Using the &lt;strong&gt;WinRT&lt;/strong&gt; component, you just have to use the following line to create a &lt;em&gt;Document&lt;/em&gt; (which is the class used to interact with a &lt;strong&gt;PDF &lt;/strong&gt;or a &lt;strong&gt;XPS&lt;/strong&gt;):&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;pdfDocument = &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Document&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Create(readBuffer, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DocumentType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.PDF, (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)Windows.Graphics.Display.&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DisplayProperties&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.LogicalDpi);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To draw a page, you just have to use the previous &lt;em&gt;pdfDocument&lt;/em&gt; object and call the &lt;em&gt;DrawPage&lt;/em&gt; method:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;pdfDocument.DrawPage(PageNumber, buf, 0, 0, width, height, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This method draws a given page inside a &lt;em&gt;IBuffer&lt;/em&gt;. To create it you just have to instantiate a &lt;em&gt;WriteableBitmap &lt;/em&gt;and the inner &lt;em&gt;PixelBuffer&lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;size = Document.GetPageSize(PageNumber);
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)(size.X * ZoomFactor);
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)(size.Y * ZoomFactor);

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;image = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;WriteableBitmap&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(width, height);
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IBuffer &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;buf = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Buffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(image.PixelBuffer.Capacity);
buf.Length = image.PixelBuffer.Length;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The buffer is then copied back to the &lt;em&gt;WriteableBitmap&lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;stream = buf.AsStream())
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;stream.CopyToAsync(image.PixelBuffer.AsStream());
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And finally the result is displayed on screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2671.image_5F00_38284D46.png"&gt;&lt;u&gt;&lt;/u&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6472.image_5F00_thumb_5F00_0D749489.png" width="640" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can even display two pages on the same image:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Task&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(() =&amp;gt; pdfDocument.DrawFirtPageConcurrent(PageNumber, buf, width, height));
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Task&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(() =&amp;gt; pdfDocument.DrawSecondPageConcurrent(PageNumber + 1, buf, width, height));&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4010.image_5F00_4EFCFE86.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4722.image_5F00_thumb_5F00_6C968B98.png" width="640" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using the mouse or the touch you can obviously navigate inside the document or zoom on pages. And with the power of vectorized PDF, you will always have the best display quality:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1777.image11_5F00_35A95E4C.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1108.image11_5F00_thumb_5F00_699890A3.png" width="640" height="398" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="center"&gt;&lt;em&gt;Optical zoom (bitmap based)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8524.image14_5F00_7382A370.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5383.image14_5F00_thumb_5F00_41460BF7.png" width="640" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="center"&gt;&lt;em&gt;Vectorized zoom&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To display these images, I used a simple FlipView so that I do not have to bother about gestures. The &lt;em&gt;DataTemplate&lt;/em&gt; used for every page is based on a &lt;em&gt;ScrollViewer&lt;/em&gt; in order to automaticaly handle zoom in and zoom out:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Name&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;flipView&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView.ItemTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;DataTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;ScrollViewer
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;ZoomMode&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Enabled&amp;quot; 
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalScrollMode&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;VerticalScrollMode&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;VerticalSnapPointsType&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;None&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalSnapPointsType&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;None&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalScrollBarVisibility&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;VerticalScrollBarVisibility&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;MinZoomFactor&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;1&amp;quot;            
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;MaxZoomFactor&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;4&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Image &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Source&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Binding &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Image&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Width&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Binding &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Width&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Height&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Binding &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Height&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;}&amp;quot; &lt;br /&gt;                       &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Stretch&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Uniform&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Center&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Margin&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;0&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;ScrollViewer&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;DataTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView.ItemTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Simple, isn’t it ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10411030" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="Windows 8" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/" /><category term="WinRT" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/" /><category term="PDF" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/PDF/" /></entry><entry><title>Faites partie du futur Instagram ou Facebook :)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/10/faites-partie-du-futur-instagram-ou-facebook.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/10/faites-partie-du-futur-instagram-ou-facebook.aspx</id><published>2013-04-10T11:18:00Z</published><updated>2013-04-10T11:18:00Z</updated><content type="html">&lt;p&gt;&lt;span class="userContent"&gt;Chers d&amp;eacute;veloppeurs, &amp;nbsp;je vous propose d'inviter ceux d'entre vous qui sont int&amp;eacute;ress&amp;eacute;s &amp;agrave; une apr&amp;egrave;s-midi de rencontres avec des dipl&amp;ocirc;m&amp;eacute;s de l'Ecole Sup&amp;eacute;rieure de Commerce de Paris.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Ces dipl&amp;ocirc;m&amp;eacute;s ont mont&amp;eacute; des projets, trouv&amp;eacute; et mis en place le design, fais le business plan, r&amp;eacute;alis&amp;eacute; les &amp;eacute;tudes de march&amp;eacute;s et parfois m&amp;ecirc;me commenc&amp;eacute; le marketing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: x-large;"&gt;Il ne leur manque que &lt;strong&gt;VOUS :)&lt;span class="userContent"&gt;&lt;img style="float: right; max-width: 550px;" src="http://blog.psychopium.com/wp-content/uploads/2012/04/reussite.jpg" alt="" width="332" height="233" border="0" /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; Que vous soyez motiv&amp;eacute;s pour partager votre temps perso avec eux ou que vous ayez envie de rejoindre le projet en tant que &lt;strong&gt;CTO&lt;/strong&gt;, venez assister &amp;agrave; leurs pitchs et faites vos courses.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Si vous &amp;ecirc;tes int&amp;eacute;ress&amp;eacute;s, envoyez moi un &lt;a href="mailto:davca@microsoft.com"&gt;mail&lt;/a&gt;. Le pitch aura lieu le 18/04 &amp;agrave; &lt;a href="http://spark.microsoft.fr"&gt;Spark&lt;/a&gt; en mode "cosy".&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10409951" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>WinRT component: How to generate a GUID?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/03/25/winrt-component-how-to-generate-a-guid.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/25/winrt-component-how-to-generate-a-guid.aspx</id><published>2013-03-25T13:39:23Z</published><updated>2013-03-25T13:39:23Z</updated><content type="html">&lt;p&gt;For your Windows 8 applications, you may need to generate a &lt;strong&gt;unique&lt;/strong&gt; identifier (for instance, if you want to uniquely identify your users).&lt;/p&gt;  &lt;p&gt;To do so, here is a small C++ WinRT component (I decided not to use C# to make the component light-weighted because it is pure native code and so you do not need to load the CLR to use it).&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#pragma once
#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Objbase.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;UrzaBox
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public ref class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Tools &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sealed
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
        Tools();

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;static &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;String&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ GetNewID()
        {
            &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;result;
            &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = CoCreateGuid(&amp;amp;result);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
            {
                &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Guid &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;gd(result);
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;gd.ToString();
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;throw &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Exception&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::CreateException(hr);
        }
    };
}&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10405089" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="C++" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/C_2B002B00_/" /><category term="WinRT" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/" /><category term="GUID" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/GUID/" /></entry><entry><title>Create a custom user control using JavaScript and WinJS for Windows 8</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/03/19/create-a-custom-user-control-using-javascript-and-winjs-for-windows-8.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/19/create-a-custom-user-control-using-javascript-and-winjs-for-windows-8.aspx</id><published>2013-03-19T13:08:31Z</published><updated>2013-03-19T13:08:31Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3782.VDav_5F00_4DC8C566.png"&gt;&lt;img title="VDav" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="VDav" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0640.VDav_5F00_thumb_5F00_2C691FCA.png" width="600" height="200" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you may know, you can easily develop native applications for &lt;strong&gt;Windows 8&lt;/strong&gt; using &lt;strong&gt;JavaScript&lt;/strong&gt; and &lt;strong&gt;WinJS&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Among a lot of other things, &lt;strong&gt;WinJS&lt;/strong&gt; allows you to create custom control in order to factorize your UI.&lt;/p&gt;  &lt;p&gt;Today, I would like to show you how to create this kind of control and to do so, please let me introduce you with the final version of the control:&lt;/p&gt;  &lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;  &lt;!--more--&gt;  &lt;p&gt;As you can see, this is a 3D carousel that can be used to display a long list of items alongside a great (if you like it&lt;img class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2766.wlEmoticon_2D00_smile_5F00_18B3BDC6.png" /&gt;) mirror.&lt;/p&gt;  &lt;p&gt;The sample Visual Studio 2012 project can be &lt;a href="http://www.catuhe.com/msdn/darkstone.zip"&gt;downloaded here&lt;/a&gt;.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;(If you want to know how to achieve the same goal but with C# and XAML, you can read this article written by my colleague Sébastien Pertus: &lt;a title="http://blogs.msdn.com/b/mim/archive/2013/03/19/create-a-custom-user-control-using-xaml-and-c-for-windows-8.aspx" href="http://blogs.msdn.com/b/mim/archive/2013/03/19/create-a-custom-user-control-using-xaml-and-c-for-windows-8.aspx"&gt;http://blogs.msdn.com/b/mim/archive/2013/03/19/create-a-custom-user-control-using-xaml-and-c-for-windows-8.aspx&lt;/a&gt;)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So you may now wonder how you can develop such a beautiful (!!) control. The response will be decomposed on 6 parts:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="#chap1"&gt;How to set up the layout?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap2"&gt;Declaring and instancing the control&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap3"&gt;Using templates&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap4"&gt;Using data binding&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap5"&gt;Integrating user inputs and animations&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap6"&gt;Adding events&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap7"&gt;Optimizations&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; &lt;a id="chap1"&gt;&lt;/a&gt;  &lt;h1&gt;How to set up the layout?&lt;/h1&gt;  &lt;p&gt;The control itself is built using a grid (&lt;a href="http://www.w3.org/TR/css3-grid/"&gt;CSS3 Grid&lt;/a&gt;) defined as the “&lt;em&gt;&lt;strong&gt;carousel-viewport&lt;/strong&gt;&lt;/em&gt;”. Inside the viewport there are two items: one called the “&lt;em&gt;&lt;strong&gt;carousel-container&lt;/strong&gt;&lt;/em&gt;” to handle all items and one called “&lt;em&gt;&lt;strong&gt;carousel-mirror&lt;/strong&gt;&lt;/em&gt;” for the mirror (obviously).&lt;/p&gt;  &lt;p&gt;Every item is built inside a “&lt;em&gt;&lt;strong&gt;carousel-item-container&lt;/strong&gt;&lt;/em&gt;” and contains two parts: a “&lt;em&gt;&lt;strong&gt;carousel-item&lt;/strong&gt;&lt;/em&gt;” for the standard part and a “&lt;em&gt;&lt;strong&gt;carousel-mirror-item&lt;/strong&gt;&lt;/em&gt;” for the mirror part.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5808.clip_5F00_image002_5F00_515E67D3.jpg"&gt;&lt;img title="clip_image002" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6560.clip_5F00_image002_5F00_thumb_5F00_76E7E534.jpg" width="609" height="381" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can then use the magic of &lt;strong&gt;CSS&lt;/strong&gt; in order to completely style every part of the control:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-item &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{    
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;transition&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;transform 0.1s ease&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}

&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-item:hover &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;transform&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;scale(0.95)&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;For instance, with these rules, I added a cool hover effect to my items. &lt;strong&gt;Simple&lt;/strong&gt;, isn’t it? &lt;/p&gt;
&lt;a id="chap2"&gt;&lt;/a&gt;

&lt;h1&gt;Declaring and instancing the control&lt;/h1&gt;

&lt;p&gt;To declare a custom control, you just have to declare a &lt;strong&gt;WinJS&lt;/strong&gt; class:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
    &lt;span style="background: white; color: green;"&gt;// Constructor&lt;br /&gt;    &lt;/span&gt;},
    {&lt;span style="background: white; color: green;"&gt;// Instance members
    &lt;/span&gt;}, 
    {&lt;span style="background: white; color: green;"&gt;// Static members
    &lt;/span&gt;});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The first argument of the &lt;i&gt;WinJS.Class.define&lt;/i&gt; function is the constructor of you control (used to instantiate your class), the second one is the list of instance members and the last one is the list of static members.&lt;/p&gt;

&lt;p&gt;Inside the constructor, you have to define the root &lt;strong&gt;DOM&lt;/strong&gt; elements you want to use. The instance members can be properties or public functions you want to make available.&lt;/p&gt;

&lt;p&gt;For our control, the constructor will produce the layout with the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element = element || document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.winControl = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = -1;

        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Root element
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-viewport&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Items element
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.appendChild(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspectiveOrigin = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;50% 50%&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.backgroundColor = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;Black&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The constructor is also responsible for initialization options:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;i&gt;maxVisibleItems&lt;/i&gt;: Count of items visible on each side of the current item&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;depth&lt;/i&gt;: Depth of each item relatively to previous&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;animationSpeed &lt;/i&gt;: Speed of the animation when you change the current item&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;mirrorEnabled&lt;/i&gt;: Define if the mirror is visible&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;perspective&lt;/i&gt;: Value indicating the amount of perspective&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These options are defined by the user during the &lt;strong&gt;instantiation&lt;/strong&gt; of the control:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;carousel&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;DarkStone.Controls.Carousel&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-options&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{mirrorEnabled: true}&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The instance of your class can be retrieved using the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#carousel&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).winControl;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Every exposed properties can also be manipulated by the client. Here is for instance, how a slider can control the &lt;strong&gt;perspective&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#perspective&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).onchange = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    carousel.perspective = element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#perspective&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).value;
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And the result:&lt;/p&gt;

&lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-perspective.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-perspective.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;

&lt;p&gt;In addition to the previous properties, our control also exposes some other useful members (always defined with the &lt;em&gt;WinJS.Class.define&lt;/em&gt; function):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Code hidden for readability
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;},
{
    _doBinding: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Code hidden for readability
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;},
    refreshLayout: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Code hidden for readability
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;},
    element: {
        get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element; }
    },
    itemRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Main item template
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender = value;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
        }
    },
    mirrorRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror template
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender = value;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
        }
    },
    itemsSource: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Data source
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(source) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = source;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
        }
    },
    selectedIndex: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selected index
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex; },
        set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index &amp;lt; 0 || index &amp;gt;= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length || index == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex)
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = index;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        }
    },
&lt;span style="background: white; color: green;"&gt;    // more code…       &lt;/span&gt;&lt;br /&gt; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span style="background: white; color: black;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;a id="chap3"&gt;&lt;/a&gt;

&lt;h1&gt;Using templates&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;WinJS&lt;/strong&gt; also provides a way to generate item content based on templates. For our control, I decided to use two templates: one for the item and one for the mirror.&lt;/p&gt;

&lt;p&gt;The user can define his templates like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateDiv&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;img &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-bind&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;src: imageUrl&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateImg&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;mirrorTemplate&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;mirrorContainer&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;img &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-bind&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;src: imageUrl&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateImg&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;opacityMask&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The templates are retrieved from the web page:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender.winControl;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;mirrorTemplate= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender.winControl;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And used to create the &lt;strong&gt;DOM&lt;/strong&gt; content:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;template.render(data, item);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;These templates are used by a function called &lt;i&gt;createItem&lt;/i&gt; which takes a data from the data source and generate &lt;strong&gt;DOM&lt;/strong&gt; objects using templates:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Create item
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;createItem = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(data) {
    &lt;span style="background: white; color: green;"&gt;// Creating DOM element and setting correct position
    &lt;/span&gt;&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    root.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
    root.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.opacity = 0;
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    WinJS.Utilities.addClass(root, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
&lt;br /&gt;    that._itemsRoot.appendChild(root);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    root.appendChild(item);

    WinJS.Utilities.addClass(item, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Template
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template.render(data, item);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(mirrorTemplate) {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Clone for mirror
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;clone = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        mirrorTemplate.render(data, clone);
        WinJS.Utilities.addClass(clone, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        root.appendChild(clone);
        clone.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;translateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ item.clientHeight + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px) rotateX(180deg)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
    
    that._itemsRoot.removeChild(root);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root;
};&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap4"&gt;&lt;/a&gt;

&lt;p&gt;This function generates the correct class for each part of the item. This will allow you to &lt;strong&gt;skin&lt;/strong&gt; them easily. For instance, using the following templates:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateDiv&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;mirrorTemplate&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And the following &lt;strong&gt;CSS&lt;/strong&gt; rules:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-item &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{    
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;background-color&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;red&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}

&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-mirror-item &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;background-color&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;blue&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You will obtain the following result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4341.image_5F00_356D32DB.png"&gt;&lt;img title="image" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1602.image_5F00_thumb_5F00_7024B5E4.png" width="644" height="350" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;Using data binding&lt;/h1&gt;

&lt;p&gt;The user can define data using a property called &lt;i&gt;itemsSource&lt;/i&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;itemsSource: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Data source
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(source) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = source;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
    }
},&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can use a simple array or a&lt;i&gt; WinJS.Binding.List&lt;/i&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#carousel&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).winControl;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;list = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;WinJS.Binding.List();

list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic01.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic02.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic03.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic04.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic05.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic06.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});

carousel.itemsSource = list;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Once the &lt;i&gt;itemsSource&lt;/i&gt; is set, the control just have to browse it and call &lt;i&gt;createItem&lt;/i&gt; for each element.&lt;/p&gt;

&lt;p&gt;If you use a &lt;i&gt;WinJS.Binding.List&lt;/i&gt;, the control can also handle two events to &lt;strong&gt;dynamically&lt;/strong&gt; support insertion and deletion of items:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Events
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(usingBindingList) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;itemremoved&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item removed
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;previous = that._items.splice(evt.detail.index, 1)[0];

        that._itemsRoot.removeChild(previous);

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.detail.index &amp;lt; that.selectedIndex) {
            that.selectedIndex--;
        } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - evt.detail.index) &amp;lt;= that.maxVisibleItems) {
            that.refreshLayout();
        }
    });
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;iteminserted&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item inserted
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = evt.detail.index;
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;newOne = createItem(that._source.getAt(current));

        that._items.splice(evt.detail.index, 0, newOne);

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - current) &amp;lt;= that.maxVisibleItems) {
            that.refreshLayout();
        }
    });
}&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap5"&gt;&lt;/a&gt;

&lt;p&gt;Using this events, if the user executes this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#button1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).onclick = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    list.splice(0, 1); &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Removing first item
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;};

element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#button2&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).onclick = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic01.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});  &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Adding new item
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic02.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}); &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Adding new item
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The list will behave like this:&lt;/p&gt;

&lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-events.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-events.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;

&lt;h1&gt;Integrating user inputs and animations&lt;/h1&gt;

&lt;p&gt;To respond to user inputs, you just have to handle&lt;strong&gt; pointer events&lt;/strong&gt;. The pointer events (&lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx"&gt;more about here&lt;/a&gt;) are used to unify mouse, touch and pens inside a single event model. So for our control, you just have to add the following code to handle all kind of inputs:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Pointer events
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.onmspointerdown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    initialOffset = evt.clientX;

    leftButtonDown = evt.buttons == 1;

    that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
};

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.onmspointermove = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!leftButtonDown)
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;moveThreshold = 40; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// 40px for a slide

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(evt.clientX - initialOffset) &amp;gt; moveThreshold) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.clientX &amp;lt; initialOffset) {
            that.selectedIndex++;
        } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
            that.selectedIndex--;
        }
        that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
};

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.onmspointerup = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The principle is simple: if the user moves his finger/mouse/pen over more than &lt;strong&gt;40&lt;/strong&gt; pixels, we can change the current item according to the direction of the movement.&lt;/p&gt;

&lt;p&gt;To create a good looking control, you must ensure that every update of the layout is animated (fast and fluid!). To do so, you may have noticed that every “&lt;em&gt;carousel-item-container&lt;/em&gt;” has a &lt;strong&gt;CSS&lt;/strong&gt; style to define transitions:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;root.style.transition = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;transform &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s ease-in-out, opacity &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s linear&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This transition defines that every change on the &lt;em&gt;transform&lt;/em&gt; and &lt;em&gt;opacity&lt;/em&gt; properties is not immediate but animated from its original value to the final value during a specific duration.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you want to learn more about &lt;b&gt;CSS3 Transitions&lt;/b&gt;, you can go just &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/css3-transitions.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To take advantage of this &lt;strong&gt;great&lt;/strong&gt; feature, the code just have to change the transformation and the opacity of each item.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The transformation itself (&lt;a href="http://www.w3.org/TR/css3-3d-transforms/"&gt;CSS 3D Transforms&lt;/a&gt;) allows elements styled with &lt;strong&gt;CSS&lt;/strong&gt; to be transformed in two-dimensional or three-dimensional space.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The transform matrix is built using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;depth = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rotation = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : ((current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -45 : 45);
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;offset = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : ((current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth : &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth);

&lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Transform
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;rotateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ rotation + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;deg) translate3d(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ &lt;br /&gt;                        (((current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) * &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth) + offset) + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px, 0px, &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ depth + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To summarize, the items are transformed according to the following schema:&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4442.clip_5F00_image004_5F00_4BCFAB95.jpg"&gt;&lt;img title="clip_image004" style="display: inline; background-image: none;" border="0" alt="clip_image004" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5126.clip_5F00_image004_5F00_thumb_5F00_1F4E797E.jpg" width="609" height="387" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem you can face when dealing with &lt;strong&gt;CSS 3D Transforms&lt;/strong&gt; is about &lt;em&gt;zIndex&lt;/em&gt;. Indeed, when you move objects using matrices, something objects may overlap in a wrong order.&lt;/p&gt;

&lt;p&gt;For resolving this issue, you just have to correctly organize the &lt;em&gt;zIndex&lt;/em&gt; value of your items:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Z-Index
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;total = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length;
item.style.zIndex = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? total + 1 : total - Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Using this code, you can ensure that items are rendered in the correct order (depending on their distance to the selected item).&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;opacity&lt;/em&gt; is computed using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Opacity
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;currentOpacity;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) {
    currentOpacity = 1;
    
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;} &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    currentOpacity = 1.0 - (Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap6"&gt;&lt;/a&gt;

&lt;p&gt;Every item has an &lt;em&gt;opacity&lt;/em&gt; proportional to its distance from the current item:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8015.image_5F00_76CF9769.png"&gt;&lt;img title="image" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/7776.image_5F00_thumb_5F00_30723154.png" width="450" height="294" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;a id="chap6"&gt;&lt;/a&gt;

&lt;h1&gt;Adding events&lt;/h1&gt;

&lt;p&gt;Obviously, a good control must raise events. For instance, if an user select an item, it would be nice to raise a “&lt;em&gt;selectedindexchanged&lt;/em&gt;”.&lt;/p&gt;

&lt;p&gt;For our control, first of all you have to “dispatch” the event with the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;selectedIndex: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selected index
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex; },
    set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index &amp;lt; 0 || index &amp;gt;= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length || index == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex)
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = index;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();

        &lt;/span&gt;&lt;strong&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.dispatchEvent(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white; color: black;"&gt;&lt;strong&gt;, {
            selectedIndex: index
        });&lt;/strong&gt;
    }
},&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;When the user changes the &lt;em&gt;selectedIndex&lt;/em&gt;, we just have to raise the event with &lt;em&gt;dispatchEvent &lt;/em&gt;function of the control.&lt;/p&gt;

&lt;p&gt;But the control will not natively provide this function. To add it, you just have to call a small WinJS function:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;WinJS.Class.mix(DarkStone.Controls.Carousel,
    WinJS.Utilities.createEventProperties(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;),
    WinJS.UI.DOMEventMixin);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;With only these lines, you can add event listener on your control like any other control:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;carousel.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {

});&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap7"&gt;&lt;/a&gt;

&lt;h1&gt;Optimizations&lt;/h1&gt;

&lt;p&gt;Finally, just to be sure our control works well on very low end hardware, we must ensure that only visible items are effectively handled by the &lt;strong&gt;DOM&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In order to achieve this goal, we just have to remove items from the &lt;strong&gt;DOM&lt;/strong&gt; when their opacity is inferior or equal to 0. Obviously you must re-inject them when they become visible again:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Opacity
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;currentOpacity;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) {
    currentOpacity = 1;
    
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!isPresentInsideDOM) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    }
} &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    currentOpacity = 1.0 - (Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Virtualization
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;lt;= 0 &amp;amp;&amp;amp; isPresentInsideDOM) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.removeChild(item);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;gt; 0 &amp;amp;&amp;amp; !isPresentInsideDOM) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    }
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Using this code, we are now ready to handle &lt;strong&gt;thousands&lt;/strong&gt; of items even on a low end devices.&lt;/p&gt;

&lt;p&gt;The control is now complete, feel free to use it in &lt;a href="http://www.catuhe.com/msdn/darkstone.zip"&gt;your own app&lt;/a&gt; &lt;img class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1588.wlEmoticon_2D00_winkingsmile_5F00_0067DFD3.png" /&gt;&lt;/p&gt;

&lt;h1&gt;Going further&lt;/h1&gt;

&lt;p&gt;If you want to read more about some subjects I addressed in this article, here are some links you may find useful:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/css3-transitions.aspx"&gt;CSS3 Transitions&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx"&gt;Pointer events&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.w3.org/TR/css3-3d-transforms/"&gt;CSS 3D Transform&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.w3.org/TR/css3-grid/"&gt;CSS3 Grid&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/20/how-to-cook-a-windows-8-application-with-html5-javascrip-css3-rtm-version.aspx"&gt;How to cook a complete Windows 8 app using HTML5/JavaScript and CSS3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;Complete code&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;complete&lt;/strong&gt; code can be downloaded &lt;a href="http://www.catuhe.com/msdn/darkstone.zip"&gt;here&lt;/a&gt; or you can copy/paste from here:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element = element || document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.winControl = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = -1;

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Root element
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-viewport&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Items element
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.appendChild(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspectiveOrigin = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;50% 50%&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.backgroundColor = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;Black&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items = [];
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth = 0;

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Default values
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems = 15;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth = 100;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed = 0.3;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.perspective = 800;

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Options
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(options) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.depth = options.depth || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.animationSpeed = options.animationSpeed || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.perspective = options.perspective || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.perspective;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled = options.mirrorEnabled || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems = options.maxVisibleItems || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems;
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror);
            }

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Pointer events
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;that = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;initialOffset = 0;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;MSPointerDown&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
                initialOffset = evt.clientX;

                leftButtonDown = evt.buttons == 1;

                that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;MSPointerMove&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!leftButtonDown)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;moveThreshold = 40; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// 40px for a slide

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(evt.clientX - initialOffset) &amp;gt; moveThreshold) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.clientX &amp;lt; initialOffset) {
                        that.selectedIndex++;
                    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
                        that.selectedIndex--;
                    }
                    that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                }
            }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;MSPointerUp&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
                leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        },
    {
        _doBinding: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source || !&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender || (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled &amp;amp;&amp;amp; !&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender))
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;usingBindingList = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.getAt !== undefined&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender.winControl;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;mirrorTemplate;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender)
                mirrorTemplate = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender.winControl;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;that = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;onItemClick = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selecting the current item
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;newOne = that._items.indexOf(evt.currentTarget.parentElement);
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!that._pageChanged) {
                    that.selectedIndex = newOne;
                }
            };

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Browse data source
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length; index++) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items[index];
                
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(item.parentElement) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.removeChild(item);
                }
            }
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items = [];

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create item
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;createItem = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(data, initalTransform) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                root.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(initalTransform)
                    root.style.transform = initalTransform;
                root.style.transition = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;transform &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s ease-in-out, opacity &amp;quot; &lt;br /&gt;                                                     &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s linear&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.opacity = 0;
                root.onmousemove = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
                    evt.preventDefault(); &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Preventing picture manipulation
                &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;};
                WinJS.Utilities.addClass(root, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

                that._itemsRoot.appendChild(root);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                root.appendChild(item);

                item.onclick = onItemClick;
                WinJS.Utilities.addClass(item, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Template
                &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template.render(data, item);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(mirrorTemplate) {
                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Clone for mirror
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;clone = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                    mirrorTemplate.render(data, clone);
                    WinJS.Utilities.addClass(clone, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                    root.appendChild(clone);
                    clone.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;translateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ item.clientHeight + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px) rotateX(180deg)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                }
                
                that._itemsRoot.removeChild(root);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root;
            };

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Browse data source
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.length; index++) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;data = usingBindingList ? &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.getAt(index) : &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source[index];

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.push(createItem(data));
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = 0;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Events
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(usingBindingList) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;itemremoved&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item removed
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;previous = that._items.splice(evt.detail.index, 1)[0];

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(previous.parentElement) {
                        that._itemsRoot.removeChild(previous);
                    }

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.detail.index &amp;lt; that.selectedIndex) {
                        that.selectedIndex--;
                    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - evt.detail.index) &amp;lt;= that.maxVisibleItems) {
                        that.refreshLayout();
                    }
                });
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;iteminserted&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item inserted
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = evt.detail.index;
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;newOne = createItem(that._source.getAt(current));

                    that._items.splice(evt.detail.index, 0, newOne);

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - current) &amp;lt;= that.maxVisibleItems) {
                        that.refreshLayout();
                    }
                });
            }

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;translateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.element.clientHeight / 2 + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        },
        refreshLayout: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length == 0) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;total = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; total; index++) {

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items[current];
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;isPresentInsideDOM = (item.parentElement !== &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Opacity
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;currentOpacity;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) {
                    currentOpacity = 1;
                    
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!isPresentInsideDOM) {
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
                        isPresentInsideDOM = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    }
                } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
                    currentOpacity = 1.0 - (Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems);

                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Virtualization
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;lt;= 0 &amp;amp;&amp;amp; isPresentInsideDOM) {
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.removeChild(item);
                        isPresentInsideDOM = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;gt; 0 &amp;amp;&amp;amp; !isPresentInsideDOM) {
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
                        isPresentInsideDOM = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    }
                }

                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Setting opacity
                &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.opacity = currentOpacity;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(isPresentInsideDOM) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth)
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth = item.clientWidth;

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;depth = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth;
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rotation = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : ((current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -45 : 45);
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;offset = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : (&lt;br /&gt;                                             (current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth : &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth);

                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Transform
                    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;rotateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ rotation + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;deg) translate3d(&amp;quot; &lt;br /&gt;                       &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ (((current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) * &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth) + offset) + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px, 0px, &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ depth + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Z-Index
                    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.zIndex = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? total + 1 : total&lt;br /&gt;                       - Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex);
                }

                current++;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length)
                    current = 0;
            }
        },
        element: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element; }
        },
        itemRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Main item template
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender = value;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
            }
        },
        mirrorRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror template
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender = value;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
            }
        },
        itemsSource: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Data source
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(source) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = source;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
            }
        },
        selectedIndex: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selected index
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex; },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index &amp;lt; 0 || index &amp;gt;= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length || index == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = index;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.dispatchEvent(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, {
                    selectedIndex: index
                });
            }
        },
        animationSpeed: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed; },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed = value;
            }
        },
        depth: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth; },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth === value)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth = value;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._refreshLayout();
            }
        },
        perspective: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;parseInt(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspective.replace(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;));
            },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspective = value + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }
        },
        maxVisibleItems: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems;
            },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems === value) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                }

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems = value;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._refreshLayout();
            }
        }
    });

    WinJS.Namespace.define(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;DarkStone.Controls&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, {
        Carousel: carousel
    });
    
    WinJS.Class.mix(DarkStone.Controls.Carousel,
        WinJS.Utilities.createEventProperties(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;),
        WinJS.UI.DOMEventMixin);
})();&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10403465" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="HTML5" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML5/" /><category term="HTML 5" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML+5/" /><category term="Javascript" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/" /><category term="CSS3" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/CSS3/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/" /><category term="WinRT" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/" /><category term="Touch" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Touch/" /><category term="User control" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/User+control/" /></entry><entry><title>TechDays 2013 - Vidéos de la plénière développeurs et des sessions Coding4Fun et Geek is in da House</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/03/08/vid-233-os-de-la-pl-233-ni-232-re-d-233-veloppeurs-et-des-sessions-coding4fun-et-geek-is-in-da-house.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/08/vid-233-os-de-la-pl-233-ni-232-re-d-233-veloppeurs-et-des-sessions-coding4fun-et-geek-is-in-da-house.aspx</id><published>2013-03-08T07:23:14Z</published><updated>2013-03-08T07:23:14Z</updated><content type="html">&lt;p&gt;Ben voila, tout est dans le titre &lt;img class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5383.wlEmoticon_2D00_smile_5F00_73E0AE4F.png" /&gt;&lt;/p&gt;  &lt;h1&gt;Développeurs c’est le chef&lt;/h1&gt; &lt;iframe height="315" src="http://www.youtube.com/embed/FnBYFCNfIPc" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;   &lt;h1&gt;Coding4Fun 2013&lt;/h1&gt; &lt;iframe height="315" src="http://www.youtube.com/embed/wTtnhal35Rc" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;   &lt;h1&gt;Geek is in the house&lt;/h1&gt; &lt;iframe height="315" src="http://www.youtube.com/embed/wVzu1HsJNiw" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10400573" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="TechDays" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/TechDays/" /><category term="Coding4Fun" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Coding4Fun/" /><category term="Geek is in the house" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Geek+is+in+the+house/" /></entry><entry><title>Developing a WinRT component to create a video file using Media Foundation</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/03/06/developing-a-winrt-component-to-create-a-video-file-using-media-foundation.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/06/developing-a-winrt-component-to-create-a-video-file-using-media-foundation.aspx</id><published>2013-03-06T10:00:09Z</published><updated>2013-03-06T10:00:09Z</updated><content type="html">&lt;p&gt;After creating a GIF file using my previous &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/how-to-create-an-animated-gif-with-winrt.aspx"&gt;article&lt;/a&gt;, I propose you to use the power of &lt;strong&gt;WinRT&lt;/strong&gt; to create a component in order to produce video file from your drawings (using for instance a canvas with &lt;strong&gt;Javascript&lt;/strong&gt;).&lt;/p&gt;  &lt;p&gt;To do so, we will use &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx"&gt;Media Foundation&lt;/a&gt; COM components. Media Foundation is the next generation multimedia platform for Windows that enables developers, consumers, and content providers to embrace the new wave of premium content with enhanced robustness, unparalleled quality, and seamless interoperability.&lt;/p&gt;  &lt;p&gt;And as I said before, Media Foundation is based on COM components. But thanks to C++ projects for Windows Store, we can create a &lt;strong&gt;WinRT&lt;/strong&gt; component on top of Media Foundation in order to use it from our &lt;strong&gt;Javascript&lt;/strong&gt; or &lt;strong&gt;.NET&lt;/strong&gt; projects.&lt;/p&gt;  &lt;p&gt;&lt;img title="DavBlog" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="DavBlog" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2543.DavBlog_5F00_0FD61986.jpg" width="600" height="338" /&gt;&lt;/p&gt;  &lt;!--more--&gt;  &lt;p&gt;This &lt;strong&gt;WinRT&lt;/strong&gt; component will be called VideoGenerator.&lt;/p&gt;  &lt;h1&gt;The VideoGenerator component&lt;/h1&gt;  &lt;p&gt;The &lt;em&gt;VideoGenerator&lt;/em&gt; class will have a main method called &lt;em&gt;AppendNewFrame&lt;/em&gt;. This method is used to add a new frame to the video.&lt;/p&gt;  &lt;p&gt;The class requires the following information to work:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Frame’s width&lt;/li&gt;    &lt;li&gt;Frame’s height&lt;/li&gt;    &lt;li&gt;Delay between frames (in milliseconds)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The class itself can be like the following:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;public ref class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sealed
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
    VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height, Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ stream,&lt;br /&gt;                   &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delay);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;virtual &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;~VideoGenerator();

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^videoFrameBuffer);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Finalize();
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Obviously, this class also requires private data to work:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoWidth;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;fps;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bitRate;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameSize;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encodingFormat;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;inputFormat;
&lt;/span&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;videoWidth&lt;/em&gt; is the width of a frame&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;videoHeight&lt;/em&gt; is the height of a frame&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;fps&lt;/em&gt; is the number of frames per second&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;bitRate&lt;/em&gt; is obviously the bits rate&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;frameSize&lt;/em&gt; is equal to &lt;em&gt;videoWidth&lt;/em&gt; * &lt;em&gt;videoHeight&lt;/em&gt;&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;encodingFormat&lt;/em&gt; defines the encoder to use (WMV for us)&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;inputFormat&lt;/em&gt; defines the format of the pixels sent to this class (RGB32)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;Initialization&lt;/h1&gt;

&lt;p&gt;Starting with this information, here is the constructor:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;br /&gt;                               Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    videoWidth = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    videoHeight = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    fps = 25;
    bitRate = 400000;
    frameSize = videoWidth * videoHeight;
    encodingFormat = MFVideoFormat_WMV3;
    inputFormat = MFVideoFormat_RGB32;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = CoInitializeEx(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;COINIT_APARTMENTTHREADED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFStartup(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;MF_VERSION&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
        {
            hr = InitializeSinkWriter(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
            {
                initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                rtStart = 0;
                rtDuration = (10000000 * &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;) / 1000;
            }
        }
    }
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This method needs to initialize COM engine (&lt;em&gt;CoInitializeEx&lt;/em&gt;) and also needs to initialize Media Foundation (&lt;em&gt;MFStartup&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;To compile you will need the following includes:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Windows.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfapi.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfidl.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Mfreadwrite.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mferror.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;wrl\client.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;memory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;u&gt;Please note that the bigger the &lt;em&gt;bitRate&lt;/em&gt; is the bigger the file will be.&lt;/u&gt; 

&lt;p&gt;The next step after initializing things is to create a sink writer (&lt;em&gt;IMFSinkWriter&lt;/em&gt;) which is used to control writings to the output file.&lt;/p&gt;

&lt;p&gt;The sink writer enables you to author media files by passing in uncompressed or encoded data. For example, you can use it to re-encode a video file, or to capture live video from a webcam to a file.&lt;/p&gt;

&lt;p&gt;In our case we will use it by passing uncompressed data from .NET or javascript.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::InitializeSinkWriter(Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{    
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFAttributes&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spAttr;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeOut;   
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeIn;           
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFByteStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spByteStream;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMFByteStreamOnStreamEx((&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IUnknown&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &amp;amp;spByteStream);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {        
        MFCreateAttributes(&amp;amp;spAttr, 10);
        spAttr-&amp;gt;SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        hr = MFCreateSinkWriterFromURL(L&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.wmv&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, spByteStream.Get(), spAttr.Get(), &amp;amp;sinkWriter);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the output media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeOut);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_SUBTYPE, encodingFormat);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_AVG_BITRATE, bitRate);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeOut.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;AddStream(mediaTypeOut.Get(), &amp;amp;streamIndex);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the input media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeIn);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_SUBTYPE, inputFormat);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeIn.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;SetInputMediaType(streamIndex, mediaTypeIn.Get(), &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Tell the sink writer to start accepting data.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;BeginWriting();
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Starting from a WinRT Stream, you have to call &lt;em&gt;MFCreateMFByteStreamOnStreamEx&lt;/em&gt; method to convert it to a &lt;em&gt;IMFByteStream&lt;/em&gt; object. Then using &lt;em&gt;MFCreateSinkWriterFromURL&lt;/em&gt; you can grab the sink writer.&lt;/p&gt;

&lt;p&gt;The following part of the code is dedicated to configure the input and output format of the sink writer accordingly to defined parameters (&lt;em&gt;mediaTypeOut&lt;/em&gt; and &lt;em&gt;mediaTypeIn&lt;/em&gt; objects).&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;mediaTypeOut&lt;/em&gt; is responsible for:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms702272(v=vs.85).aspx"&gt;MF_MT_MAJOR_TYPE&lt;/a&gt;: The main type of the file (Video here)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms700208(v=vs.85).aspx"&gt;MF_MT_SUBTYPE&lt;/a&gt;: The subtype (WMV here)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-nz/library/windows/desktop/ms703792"&gt;MF_MT_AVG_BITRATE&lt;/a&gt;: The bit rate or the compression rate if you will (Defines the quality of the video)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms694868(VS.85).aspx"&gt;MF_MT_INTERLACE_MODE&lt;/a&gt;: Interlace mode (Progressive for us)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms701619(VS.85).aspx"&gt;MF_MT_FRAME_SIZE&lt;/a&gt;: The size of the frame (width and height)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms700140(v=vs.85).aspx"&gt;MF_MT_FRAME_RATE&lt;/a&gt;: Frame per second&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms704767(VS.85).aspx"&gt;MF_MT_PIXEL_ASPECT_RATIO&lt;/a&gt;: Aspect ratio&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;em&gt;mediaTypeIn&lt;/em&gt; is responsible for:&lt;/p&gt;

&lt;ul&gt;&lt;!--StartFragment--&gt;
  &lt;li&gt;MF_MT_MAJOR_TYPE: The main type of the file (Video here)&lt;/li&gt;

  &lt;li&gt;MF_MT_SUBTYPE: The subtype (RGB32 here)&lt;/li&gt;

  &lt;li&gt;MF_MT_INTERLACE_MODE: Interlace mode (Progressive for us)&lt;/li&gt;

  &lt;li&gt;MF_MT_FRAME_SIZE: The size of the frame (width and height)&lt;/li&gt;

  &lt;li&gt;MF_MT_FRAME_RATE: Frame per second&lt;/li&gt;

  &lt;li&gt;MF_MT_PIXEL_ASPECT_RATIO: Aspect ratio&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;Adding a new frame&lt;/h1&gt;

&lt;p&gt;Once we have a sink writer, you just have to append new frame by sending a byte array to the component:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;length = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Length / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sizeof&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*buffer = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Data);
    std::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;unique_ptr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt; target(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[length]);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; length; index++)
    {
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;color = buffer[index];
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;b = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x00FF0000) &amp;gt;&amp;gt; 16);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;g = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x0000FF00) &amp;gt;&amp;gt; 8);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;r = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x000000FF));

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ARM
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;row = index / videoWidth;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;targetRow = videoHeight - row - 1;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;column = index - (row * videoWidth);
        target[(targetRow * videoWidth) + column] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#else
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;target[index] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#endif
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send frame to the sink writer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = WriteFrame(target.get(), rtStart, rtDuration);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;FAILED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;throw &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Exception&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::CreateException(hr);
    }
    rtStart += rtDuration;
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Before writing data, you have to prepare it because:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Data must be provided using RGB format and in my case (HTML5 canvas), data is stored using BGR format&lt;/li&gt;

  &lt;li&gt;On ARM devices (detected thanks to the define #ARM), data is stored starting from the last line (and not the first line) so you have to revert them on the Y axis&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, when your data is ready, just call the following code to append it to the output file:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::WriteFrame(
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Time stamp.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Frame duration.
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFSample&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; sample;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; buffer;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONG &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth = 4 * videoWidth;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbBuffer = cbWidth * videoHeight;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*pData = &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a new memory buffer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMemoryBuffer(cbBuffer, &amp;amp;buffer);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Lock the buffer and copy the video frame to the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;Lock(&amp;amp;pData, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCopyImage(
            pData,                      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination buffer.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// First row in source image.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Source stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image width in bytes.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image height in pixels.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(buffer.Get())
    {
        buffer-&amp;gt;Unlock();
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the data length of the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;SetCurrentLength(cbBuffer);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a media sample and add the buffer to the sample.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateSample(&amp;amp;sample);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;AddBuffer(buffer.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the time stamp and the duration.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleTime(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleDuration(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send the sample to the Sink Writer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;WriteSample(streamIndex, sample.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}
&lt;/span&gt;&lt;/pre&gt;
The code creates a sample, fill it with your data and set time and duration before writing the sample to the sink writer. 

&lt;h1&gt;Closing and cleaning&lt;/h1&gt;

&lt;p&gt;When you are done, you just have to call the Finalize method (and for the sake of completeness, I also add the destructor here):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::~VideoGenerator()
{
    Finalize();
}

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::Finalize()
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!initiated)
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    sinkWriter-&amp;gt;Finalize();
    MFShutdown();
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Finalization is just about closing the sink writer and release Media Foundation API (&lt;em&gt;MFShutdown&lt;/em&gt;).&lt;/p&gt;

&lt;h1&gt;Using VideoGenerator&lt;/h1&gt;

&lt;p&gt;VideoGenerator is a WinRT component so you can easily use it from .NET or Javascript. For instance, using Javascript, the client code can be something like that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;picker = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage.Pickers.FileSavePicker();
picker.fileTypeChoices.insert(Flipflop.Tools.GetString(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;VideoFiles&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;), [&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.wmv&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;]);

picker.pickSaveFileAsync().then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(file) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!file) {
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
    file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(stream) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoGenerator = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;VideoTools.VideoGenerator(800, 600, stream, 16);

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;commandsIndex = 0; commandsIndex &amp;lt; 50; commandsIndex++) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvas = document.getElementById(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;canvas&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ commandsIndex);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;context = canvas.getContext(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;data = context.getImageData(0, 0, width, height);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bytes = data.data;
            videoGenerator.appendNewFrame(bytes);
        }

        videoGenerator.finalize();
        stream.close();
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    }&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
});&lt;/span&gt;&lt;/pre&gt;

&lt;h1&gt;Complete code&lt;/h1&gt;

&lt;p&gt;The complete VideoGenerator code can be found &lt;a href="http://www.catuhe.com/msdn/VideoTools.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Or copy/paste right here.&lt;/p&gt;

&lt;h2&gt;VideoGenerator.h&lt;/h2&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#pragma once
#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Windows.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfapi.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfidl.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Mfreadwrite.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mferror.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;wrl\client.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;memory&amp;gt;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Microsoft::WRL;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;VideoTools
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public ref class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sealed
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoWidth;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;fps;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bitRate;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameSize;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encodingFormat;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;inputFormat;

        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD  &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;streamIndex;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFSinkWriter&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; sinkWriter;

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;bool   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;initiated;

        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rtStart;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT64 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rtDuration;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;private&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;InitializeSinkWriter(Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ stream);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;WriteFrame(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*videoFrameBuffer, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; rtStart, &lt;br /&gt;                           &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; rtDuration);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
        VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height, &lt;br /&gt;                       Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ stream, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delay);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;virtual &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;~VideoGenerator();

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^videoFrameBuffer);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Finalize();
    };
}
&lt;/span&gt;&lt;/pre&gt;

&lt;h2&gt;VideoGenerator.cpp&lt;/h2&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;pch.h&amp;quot;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;VideoGenerator.h&amp;quot;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#pragma comment&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;lib&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;mfreadwrite&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#pragma comment&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;lib&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;mfplat&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#pragma comment&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;lib&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;mfuuid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;VideoTools;

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;br /&gt;                               Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    videoWidth = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    videoHeight = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    fps = 25;
    bitRate = 400000;
    frameSize = videoWidth * videoHeight;
    encodingFormat = MFVideoFormat_WMV3;
    inputFormat = MFVideoFormat_RGB32;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = CoInitializeEx(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;COINIT_APARTMENTTHREADED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFStartup(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;MF_VERSION&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
        {
            hr = InitializeSinkWriter(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
            {
                initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                rtStart = 0;
                rtDuration = (10000000 * &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;) / 1000;
            }
        }
    }
}

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::~VideoGenerator()
{
    Finalize();
}

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::Finalize()
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!initiated)
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    sinkWriter-&amp;gt;Finalize();
    MFShutdown();
}

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;length = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Length / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sizeof&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*buffer = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Data);
    std::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;unique_ptr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt; target(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[length]);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; length; index++)
    {
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;color = buffer[index];
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;b = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x00FF0000) &amp;gt;&amp;gt; 16);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;g = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x0000FF00) &amp;gt;&amp;gt; 8);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;r = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x000000FF));

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ARM
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;row = index / videoWidth;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;targetRow = videoHeight - row - 1;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;column = index - (row * videoWidth);
        target[(targetRow * videoWidth) + column] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#else
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;target[index] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#endif
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send frame to the sink writer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = WriteFrame(target.get(), rtStart, rtDuration);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;FAILED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;throw &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Exception&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::CreateException(hr);
    }
    rtStart += rtDuration;
}

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::InitializeSinkWriter(Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{    
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFAttributes&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spAttr;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeOut;   
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeIn;           
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFByteStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spByteStream;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMFByteStreamOnStreamEx((&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IUnknown&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &amp;amp;spByteStream);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {        
        MFCreateAttributes(&amp;amp;spAttr, 10);
        spAttr-&amp;gt;SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        hr = MFCreateSinkWriterFromURL(L&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.wmv&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, spByteStream.Get(), spAttr.Get(), &amp;amp;sinkWriter);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the output media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeOut);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_SUBTYPE, encodingFormat);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_AVG_BITRATE, bitRate);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeOut.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;AddStream(mediaTypeOut.Get(), &amp;amp;streamIndex);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the input media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeIn);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_SUBTYPE, inputFormat);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeIn.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;SetInputMediaType(streamIndex, mediaTypeIn.Get(), &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Tell the sink writer to start accepting data.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;BeginWriting();
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::WriteFrame(
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Time stamp.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Frame duration.
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFSample&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; sample;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; buffer;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONG &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth = 4 * videoWidth;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbBuffer = cbWidth * videoHeight;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*pData = &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a new memory buffer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMemoryBuffer(cbBuffer, &amp;amp;buffer);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Lock the buffer and copy the video frame to the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;Lock(&amp;amp;pData, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCopyImage(
            pData,                      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination buffer.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// First row in source image.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Source stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image width in bytes.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image height in pixels.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(buffer.Get())
    {
        buffer-&amp;gt;Unlock();
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the data length of the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;SetCurrentLength(cbBuffer);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a media sample and add the buffer to the sample.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateSample(&amp;amp;sample);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;AddBuffer(buffer.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the time stamp and the duration.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleTime(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleDuration(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send the sample to the Sink Writer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;WriteSample(streamIndex, sample.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}
&lt;/span&gt;&lt;/pre&gt;

&lt;h1&gt;Going further&lt;/h1&gt;

&lt;p&gt;Some useful links to go further:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Media foundation doc: &lt;a title="http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx" href="http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx"&gt;http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;About Media foundation: &lt;a title="http://msdn.microsoft.com/en-us/library/windows/apps/ms696274.aspx" href="http://msdn.microsoft.com/en-us/library/windows/apps/ms696274.aspx"&gt;http://msdn.microsoft.com/en-us/library/windows/apps/ms696274.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Creating a &lt;strong&gt;WinRT&lt;/strong&gt; component – part 1:&lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/13/creating-a-winrt-component-using-c-cx-deform-a-direct2d-effect-toolkit.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/13/creating-a-winrt-component-using-c-cx-deform-a-direct2d-effect-toolkit.aspx"&gt;http://blogs.msdn.com/b/eternalcoding/archive/2012/08/13/creating-a-winrt-component-using-c-cx-deform-a-direct2d-effect-toolkit.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Creating a &lt;strong&gt;WinRT&lt;/strong&gt; component – part 2: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/28/creating-a-winrt-component-using-c-cx-part-2-adding-a-custom-direct2d-effect-to-deform.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/28/creating-a-winrt-component-using-c-cx-part-2-adding-a-custom-direct2d-effect-to-deform.aspx"&gt;http://blogs.msdn.com/b/eternalcoding/archive/2012/08/28/creating-a-winrt-component-using-c-cx-part-2-adding-a-custom-direct2d-effect-to-deform.aspx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10399839" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="C++" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/C_2B002B00_/" /><category term="WinRT" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/" /><category term="Video" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Video/" /><category term="Media Foundation" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Media+Foundation/" /><category term="WMV" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/WMV/" /></entry><entry><title>How to create an animated GIF with WinRT</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/how-to-create-an-animated-gif-with-winrt.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/how-to-create-an-animated-gif-with-winrt.aspx</id><published>2013-02-28T15:05:20Z</published><updated>2013-02-28T15:05:20Z</updated><content type="html">&lt;h1&gt;Why using GIF files?&lt;/h1&gt;  &lt;p&gt;For one of my project (&lt;strong&gt;Flipflop&lt;/strong&gt;: &lt;a href="http://apps.microsoft.com/windows/app/flipflop/99c01512-fe4f-4d1a-872e-eb9fd6638ff4"&gt;http://apps.microsoft.com/windows/app/flipflop/99c01512-fe4f-4d1a-872e-eb9fd6638ff4&lt;/a&gt;), I needed to create an animated GIF based on a group of HTML5 canvas.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5734.intro0_5F00_0B174B13.gif"&gt;&lt;img title="intro0" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="intro0" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8865.intro0_5F00_thumb_5F00_14FC3C7E.gif" width="300" height="120" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;em&gt;&lt;font size="1"&gt;A GIF produced by Flipflop&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The main goal of &lt;strong&gt;Flipflop&lt;/strong&gt; is to allow users to create an animated flipbook. And to allow them to share it, I finally found that GIF files were a great deal.&lt;/p&gt;  &lt;h1&gt;Creating a GIF using WIC components&lt;/h1&gt;  &lt;p&gt;So I propose you to share the small class that I used to achieve this goal: &lt;strong&gt;GifMaker&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;To work this class requires you to specify frames size and obviously all frames:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;System;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;System.Collections.Generic;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;System.Runtime.InteropServices.WindowsRuntime;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Foundation;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Graphics.Imaging;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Utilities
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public sealed class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GifMaker
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;readonly &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt; frames = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt;();
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;private readonly uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameWidth;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;private readonly uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameHeight;

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;GifMaker(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height)
        {
            frameWidth = width;
            frameHeight = height;
        }

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;AppendNewFrame([&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ReadOnlyArray&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;]&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[] frame)
        {
            frames.Add(frame);
        }&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This class mainly uses &lt;em&gt;&lt;strong&gt;WIC&lt;/strong&gt;&lt;/em&gt; or actually &lt;em&gt;&lt;strong&gt;Windows.Graphics&lt;/strong&gt;&lt;/em&gt; namespace. This namespace contains a class called &lt;em&gt;&lt;strong&gt;BitmapEncoder&lt;/strong&gt;&lt;/em&gt; that will allow us to generate files using specific encoders such as GifEncoder.&lt;/p&gt;

&lt;p&gt;The point is that GIF files are composed of a list of frames. You just have to browse through them and send each of them to the encoder using &lt;em&gt;&lt;strong&gt;GoToNextFrameAsync&lt;/strong&gt;&lt;/em&gt; to register a new frame:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;public &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IAsyncInfo &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;GenerateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;StorageFile &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;AsyncInfo&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;async &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ctx =&amp;gt;
        {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;outStream = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file.OpenAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;FileAccessMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.ReadWrite);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.CreateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.GifEncoderId, outStream);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; frames.Count; i++)
            {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;pixels = frames[i];
                encoder.SetPixelData(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapPixelFormat&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Rgba8, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapAlphaMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Ignore,
                                     frameWidth, frameHeight,
                                     92.0, 92.0,
                                     pixels);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(i &amp;lt; frames.Count - 1)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.GoToNextFrameAsync();
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.FlushAsync();
            outStream.Dispose();
        });
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Easy, isn’t it ?&lt;/p&gt;

&lt;h1&gt;Adding delay between frames&lt;/h1&gt;

&lt;p&gt;To be complete, you also have to handle the delay between frames and for this point, I must admit it took me a long time to figure out how to do that. &lt;/p&gt;

&lt;p&gt;The solution is handled by frame properties (&lt;strong&gt;&lt;em&gt;encoder.BitmapProperties&lt;/em&gt;&lt;/strong&gt;) and especially via the property named “/grctlext/Delay” (!!).&lt;/p&gt;

&lt;p&gt;To the final code is like the following:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;public &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IAsyncInfo &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;GenerateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;StorageFile &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delay)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;AsyncInfo&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;async &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ctx =&amp;gt;
        {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;outStream = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file.OpenAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;FileAccessMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.ReadWrite);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.CreateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.GifEncoderId, outStream);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; frames.Count; i++)
            {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;pixels = frames[i];
                encoder.SetPixelData(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapPixelFormat&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Rgba8, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapAlphaMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Ignore,
                                     frameWidth, frameHeight,
                                     92.0, 92.0,
                                     pixels);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(i == 0)
                {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;properties = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapPropertySet
                        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
                            {
                                &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/grctlext/Delay&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,
                                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapTypedValue&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(delay / 10, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;PropertyType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.UInt16)
                            }
                        };

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.BitmapProperties.SetPropertiesAsync(properties);
                }

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(i &amp;lt; frames.Count - 1)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.GoToNextFrameAsync();
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.FlushAsync();
            outStream.Dispose();
        });
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;Using it from other languages&lt;/h1&gt;

&lt;p&gt;For instance if you want to use it from &lt;strong&gt;JavaScript&lt;/strong&gt;, you just have to do something like that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;picker = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage.Pickers.FileSavePicker();
picker.fileTypeChoices.insert(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;Gif files&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, [&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.gif&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;]);

picker.pickSaveFileAsync().then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(file) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!file) {
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;gifMaker = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Utilities.GifMaker(800, 600);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;commandsIndex = 0; commandsIndex &amp;lt; currentFlipflop.pages.length; commandsIndex++) {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// This code is used to retrieve canvases bytes
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bytes = Flipflop.Tools.GetBytesfromFlipflop(currentFlipflop.pages[commandsIndex],
            800, 600);

        gifMaker.appendNewFrame(bytes);
    }

    gifMaker.generateAsync(file, 200).done();&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Obviously it works the same way from &lt;strong&gt;.NET&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3175.intro2_5F00_2FC8628A.gif"&gt;&lt;img title="intro2" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="intro2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0842.intro2_5F00_thumb_5F00_19924738.gif" width="300" height="100" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10398174" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="Canvas" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Canvas/" /><category term="C#" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/C_2300_/" /><category term="WinRT" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/" /><category term="Animated GIF" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Animated+GIF/" /></entry><entry><title>Introduction to CSS3 Transitions</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/css3-transitions.aspx" /><id>http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/css3-transitions.aspx</id><published>2013-02-28T05:54:00Z</published><updated>2013-02-28T05:54:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5635.Test2_5F00_6E27D563.jpg"&gt;&lt;img style="border-width: 0px; margin: 2px 0px 2px 4px; padding-top: 0px; padding-right: 0px; padding-left: 0px; float: right; display: inline; background-image: none;" title="Test2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0458.Test2_5F00_thumb_5F00_4BEFC9DD.jpg" alt="Test2" width="350" height="234" align="right" border="0" /&gt;&amp;nbsp;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A good-looking application&lt;/strong&gt; must provide user with visual feedback. User must always know that an order (a click, a tap or whatever) is well received and understood by the application and &lt;strong&gt;animations&lt;/strong&gt; are a great tool to do so.&lt;/p&gt;
&lt;p&gt;The new &lt;strong&gt;HTML 5&lt;/strong&gt; specification (to be honest, I should say &amp;ldquo;the new &lt;strong&gt;CSS 3&lt;/strong&gt; specification&amp;rdquo;) introduces a great tool to handle &lt;strong&gt;simple &lt;/strong&gt;animations:&lt;strong&gt; the transitions&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;According to &amp;ldquo;CSS Transitions Module Level 3&amp;rdquo; specification on &lt;a href="http://www.w3.org/TR/css3-transitions/" target="_blank"&gt;W3C site&lt;/a&gt;, CSS3 Transitions &lt;span style="font-size: small;"&gt;&lt;em&gt;allows property changes in CSS values to occur &lt;strong&gt;smoothly&lt;/strong&gt; over a specified duration&lt;/em&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The aim of this article will be to first describe the concept of transitions and then to see how CSS3 Transitions works and how we can handle browsers that don&amp;rsquo;t support the feature:&lt;img style="float: right; display: inline;" title="HTML5 Powered with CSS3 / Styling" src="http://www.w3.org/html/logo/badge/html5-badge-v-css3.png" alt="HTML5 Powered with CSS3 / Styling" width="38" height="106" align="right" /&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="#c02"&gt;CSS3 Transitions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#c03"&gt;Putting it all together&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#c01"&gt;Transitions without CSS3 Transitions&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="#c04"&gt;Conclusion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#c05"&gt;Going further&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In addition, I suggest you to read the &amp;ldquo;&lt;strong&gt;&lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx" target="_blank"&gt;Introduction to CSS3 Animations&lt;/a&gt;&lt;/strong&gt;&amp;rdquo; (by &lt;em&gt;David Rousset&lt;/em&gt;) which is an excellent companion for this article.&lt;/p&gt;
&lt;p&gt;To see how CSS3 Transitions can be used, I developed is a sample of a game which uses CSS3 Transitions to animate cells of a puzzle (and which will fallback to JavaScript if your browser doesn&amp;rsquo;t support CSS3 Transitions):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p align="center"&gt;&lt;em&gt;To launch a game, just click on &amp;ldquo;Mix it!&amp;rdquo; and try to resolve the puzzle by clicking the cells!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;iframe src="http://www.catuhe.com/msdn/transitions/index.htm" frameborder="0" width="100%" height="600"&gt; &amp;lt;p&amp;gt;Your browser does not support iframes.&amp;lt;/p&amp;gt; Click here to show the demo : &amp;lt;a href="http://www.catuhe.com/msdn/transitions/index.htm"&amp;gt;http://www.catuhe.com/msdn/transitions/index.htm&amp;lt;/a&amp;gt; &lt;/iframe&gt;&lt;/p&gt;
&lt;p align="center"&gt;The code of this game is available &lt;a href="http://www.catuhe.com/msdn/puzzle.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;&lt;a id="c02"&gt;CSS3 Transitions&lt;/a&gt;&lt;/h1&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;At the beginning, the W3C CSS workgroup resisted adding transitions to CSS arguing that transitions are not really style properties. But eventually designers and developers managed to convince them that transitions is about dynamic styles and can take place in a CSS file.&lt;/p&gt;
&lt;p&gt;According to the W3C site, CSS3 Transitions are able to animate the following types of properties: (&lt;a id="typesLink"&gt;click here to show them&lt;/a&gt;)&lt;/p&gt;
&lt;div id="types"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;color&lt;/strong&gt;: interpolated via red, green, blue and alpha components (treating each as a number, see below)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;length&lt;/strong&gt;: interpolated as real numbers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;percentage&lt;/strong&gt;: interpolated as real numbers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;integer&lt;/strong&gt;: interpolated via discrete steps (whole numbers). The interpolation happens in real number space and is converted to an integer using &lt;code&gt;floor()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;number&lt;/strong&gt;: interpolated as real (floating point) numbers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;transform list&lt;/strong&gt;: see CSS Transforms specification: &lt;a title="http://www.w3.org/TR/css3-2d-transforms/" href="http://www.w3.org/TR/css3-2d-transforms/"&gt;http://www.w3.org/TR/css3-2d-transforms/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;rectangle&lt;/strong&gt;: interpolated via the x, y, width and height components (treating each as a number).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;visibility&lt;/strong&gt;: interpolated via a discrete step. The interpolation happens in real number space between 0 and 1, where 1 is "visible" and all other values are "hidden".&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;shadow&lt;/strong&gt;: interpolated via the color, x, y and blur components (treating them as color and numbers where appropriate). In the case where there are lists of shadows, the shorter list is padded at the end with shadows whose color is transparent and all lengths (x, y, blur) are 0.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;gradient&lt;/strong&gt;: interpolated via the positions and colors of each stop. They must have the same type (radial or linear) and same number of stops in order to be animated.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;paint server&lt;/strong&gt; (SVG): interpolation is only supported between: gradient to gradient and color to color. They then work as above.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;space-separated list of above&lt;/strong&gt;: If the lists have the same number of items, each item in the list is interpolated using the rules above. Otherwise, no interpolation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;a shorthand property&lt;/strong&gt;: If all the parts of a shorthand can be animated, then interpolation is performed as if each property was individually specified.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;And the following properties must be supported for transitions:(&lt;a id="propertiesLink"&gt;click here to show them&lt;/a&gt;)&lt;/p&gt;
&lt;div id="properties"&gt;
&lt;ul&gt;
&lt;li&gt;background-color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;background-image (&lt;em&gt;only gradients&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;background-position (&lt;em&gt;percentage and length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-bottom-color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-bottom-width (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-left-color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-left-width (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-right-color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-right-width (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-spacing (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-top-color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-top-width (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;border-width (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;bottom (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;crop (&lt;em&gt;rectangle&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;font-size (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;font-weight (&lt;em&gt;number&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;grid-* (&lt;em&gt;various&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;height (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;left (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;letter-spacing (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;line-height (&lt;em&gt;number, length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;margin-bottom (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;margin-left (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;margin-right (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;margin-top (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;max-height (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;max-width (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;min-height (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;min-width (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;opacity (&lt;em&gt;number&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;outline-color (&lt;em&gt;color&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;outline-offset (&lt;em&gt;integer&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;outline-width (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;padding-bottom (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;padding-left (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;padding-right (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;padding-top (&lt;em&gt;length&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;right (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;text-indent (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;text-shadow (&lt;em&gt;shadow&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;top (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;vertical-align (&lt;em&gt;keywords, length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;visibility (&lt;em&gt;visibility&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;width (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;word-spacing (&lt;em&gt;length and percentage&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;z-index (&lt;em&gt;integer&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;zoom (&lt;em&gt;number&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;SVG&lt;/h2&gt;
&lt;p&gt;The properties of SVG objects are animatable when they are defined as &lt;strong&gt;animatable:true&lt;/strong&gt; in the SVG specification: &lt;a title="http://www.w3.org/TR/SVG/struct.html" href="http://www.w3.org/TR/SVG/struct.html"&gt;http://www.w3.org/TR/SVG/struct.html&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Declarations&lt;/h2&gt;
&lt;p&gt;To declare a transition in a CSS file, you just have to write the following code:&lt;/p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:eb02ec2c-37b8-429c-93d3-68b50d70aae3" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 500px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;transition-property&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;all&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #ff0000;"&gt;transition-duration&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;0.5s&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;transition-timing-function&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;ease&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #ff0000;"&gt;transition-delay&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;0s&lt;/span&gt;;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This declaration defines that any update on any property will be done in 0.5s (and not immediately so&lt;img class="wlEmoticon wlEmoticon-smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8171.wlEmoticon_2D00_smile_5F00_221D4FCE.png" alt="Sourire" /&gt;).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can also define your translations on a per property basis:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:63d25ede-ccbd-4201-92f2-588995d2d05f" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 300px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;transition-property&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;opacity&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;left&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;top&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #ff0000;"&gt;transition-duration&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;0.5s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0.8s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0.1s&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;transition-timing-function&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;ease&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;linear&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;ease&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #ff0000;"&gt;transition-delay&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;0s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;1s&lt;/span&gt;;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And finally you can use the shorthand property &amp;ldquo;&lt;em&gt;transition&lt;/em&gt;&amp;rdquo; to define all you need in a single line:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b378f52a-4191-4492-a3f9-3b4bcf69ad2d" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;transition&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;all&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0.5s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;ease&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0s&lt;/span&gt;;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this shorthand version you can precise as many properties as you want separated by a comma:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d2da2bb1-a9f7-4bae-859b-f966d39f65f4" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 300px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;transition&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;opacity&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0.5s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;ease&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0s,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;left&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0.8s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;linear&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0s&lt;/span&gt;;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The transitions will be triggered when a property of the target object is updated. The update can be done with &lt;strong&gt;JavaScript&lt;/strong&gt; or using CSS3 by assign &lt;strong&gt;new class to a tag&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example, using IE10 if you have the following CSS3 declaration:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:147440b1-53aa-4426-a955-e6d3a9f4af5e" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 500px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;-ms-transition-property&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;opacity&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;left&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;top&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&lt;span style="color: #ff0000;"&gt;-ms-transition-duration&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;0.5s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0.8s&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;0.5s&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;-ms-transition-timing-function&lt;/span&gt;: &lt;span style="color: #0000ff;"&gt;ease&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;linear&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;ease&lt;/span&gt;;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When you update the opacity of your tag, the current value will be animated to the new value over 0.5s with a ease timing function (which give a smooth animation).&lt;/p&gt;
&lt;h2&gt;Non linear transitions&lt;/h2&gt;
&lt;p&gt;The &amp;ldquo;transition-timing-function&amp;rdquo; line defines that the transition will not be linear but will use a timing function to produce a &lt;strong&gt;non linear&lt;/strong&gt; animation.&lt;/p&gt;
&lt;p&gt;Basically, CSS3 transitions will use &lt;a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves"&gt;cubic bezier curve&lt;/a&gt; to smooth the transition by computing different speed over its duration.&lt;/p&gt;
&lt;p&gt;The following functions are supported:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;linear&lt;/em&gt;: Constant speed&lt;/li&gt;
&lt;li&gt;&lt;em&gt;cubic-bezier&lt;/em&gt;: Speed will be computed according to a cubic bezier curve define by two control points: P0 et P1 (so you will have to define 4 values here: P0x,P0y and P1x, P1y.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;ease&lt;/em&gt;: Speed will be computed with cubic-bezier(0.25, 0.1, 0.25, 1)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;ease-in&lt;/em&gt;: Speed will be computed with cubic-bezier(0.42, 0, 1, 1)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;ease-inout&lt;/em&gt;: Speed will be computed with cubic-bezier(0.42, 0, 0.58, 1)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;ease-out&lt;/em&gt;: Speed will be computed with cubic-bezier(0, 0, 0.58, 1)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is a simulation tool (using &lt;strong&gt;SVG&lt;/strong&gt; of course&lt;img class="wlEmoticon wlEmoticon-smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8171.wlEmoticon_2D00_smile_5F00_221D4FCE.png" alt="Sourire" /&gt;) to show the impact of each timing function:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;iframe src="http://www.catuhe.com/msdn/transitions/easingfunctions.htm" frameborder="0" width="100%" height="650"&gt; &amp;lt;p&amp;gt;Your browser does not support iframes.&amp;lt;/p&amp;gt; Click here to show the demo : &amp;lt;a href="http://www.catuhe.com/msdn/transitions/easingfunctions.htm"&amp;gt;http://www.catuhe.com/msdn/transitions/easingfunctions.htm&amp;lt;/a&amp;gt; &lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;This simulator is written with &lt;strong&gt;pure JavaScript&lt;/strong&gt; code to facilitate the understanding of the function:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0dbfdd64-12d5-4d1e-b31b-d04e921cfcda" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: 1px solid #000080; color: #000000; font-family: 'Courier New', courier, monospace; font-size: 10pt;"&gt;
&lt;div style="background: #ffffff; overflow: auto; max-height: 500px;"&gt;&lt;ol style="background: #ffffff; margin: 0px; padding: 0px 0px 0px 5px;"&gt;
&lt;li&gt;TRANSITIONSHELPER.computeCubicBezierCurveInterpolation = &lt;span style="color: #0000ff;"&gt;function&lt;/span&gt; (t, x1, y1, x2, y2) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #006400;"&gt;// Extract X (which is equal to time here)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; f0 = 1 - 3 * x2 + 3 * x1;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; f1 = 3 * x2 - 6 * x1;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; f2 = 3 * x1;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; refinedT = t;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; i = 0; i &amp;lt; 5; i++) {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; refinedT2 = refinedT * refinedT;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; refinedT3 = refinedT2 * refinedT;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; x = f0 * refinedT3 + f1 * refinedT2 + f2 * refinedT;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; slope = 1.0 / (3.0 * f0 * refinedT2 + 2.0 * f1 * refinedT + f2);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; refinedT -= (x - t) * slope;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; refinedT = Math.min(1, Math.max(0, refinedT));&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #006400;"&gt;// Resolve cubic bezier for the given x&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; 3 * Math.pow(1 - refinedT, 2) * refinedT * y1 +&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 * (1 - refinedT) * Math.pow(refinedT, 2) * y2 +&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Math.pow(refinedT, 3);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;};&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This code is the implementation of the cubic bezier based on this &lt;a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves" target="_blank"&gt;definition&lt;/a&gt; and you can find the source of the simulator &lt;a href="http://www.catuhe.com/msdn/puzzle.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Delay&lt;/h2&gt;
&lt;p&gt;The &amp;ldquo;transition-delay&amp;rdquo; line defines the delay between an update of a property and the start of the transition&lt;/p&gt;
&lt;h2&gt;Events&lt;/h2&gt;
&lt;p&gt;An &lt;strong&gt;event&lt;/strong&gt; is raised at the end of a transition: &amp;ldquo;&lt;em&gt;TransitionEnd&lt;/em&gt;&amp;rdquo;. According to your browser the correct name will be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Chrome &amp;amp; Safari:&lt;em&gt; webkitTransitionEnd&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Firefox: &lt;em&gt;mozTransitionEnd&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Opera:&lt;em&gt; oTransitionEnd&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Internet Explorer:&lt;em&gt; MSTransitionEnd&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The event will give you the following information:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;propertyName&lt;/em&gt;: Name of the animated property&lt;/li&gt;
&lt;li&gt;&lt;em&gt;elapsedTime&lt;/em&gt;: The amount of time the transition has been running, in seconds&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is an usage sample for IE10:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:35b4565c-09c7-4221-ac59-5bf0ec6def65" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: 1px solid #000080; color: #000000; font-family: 'Courier New', courier, monospace; font-size: 10pt;"&gt;
&lt;div style="background: #ffffff; overflow: auto; max-height: 500px;"&gt;&lt;ol style="background: #ffffff; margin: 0px; padding: 0px 0px 0px 5px;"&gt;
&lt;li&gt;block.addEventListener(&lt;span style="color: #800000;"&gt;"MSTransitionEnd"&lt;/span&gt;, onTransitionEvent);&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;&lt;br /&gt;More about CSS3 transitions&lt;/h2&gt;
&lt;p&gt;I can mainly propose two reasons why CSS3 transitions are really useful:&lt;/p&gt;
&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;
&lt;ul&gt;&lt;!--StartFragment--&gt;
&lt;li&gt;&lt;strong&gt;Hardware acceleration:&lt;/strong&gt; CSS3 Transitions are directly handled on the GPU (where available) and produce smoother results. And it is really important on mobile devices where computing power is really limited&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Better separation between code and design&lt;/strong&gt;: For me, the developer must not be aware of animations or anything related to design. In the same way the designer/artist must not be aware of JavaScript. That&amp;rsquo;s why CSS3 Transitions are really interesting as designers can describe all the transitions in the CSS without needing developers&lt;/li&gt;
&lt;/ul&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;h1&gt;Support and fallback&lt;/h1&gt;
&lt;p&gt;Since PP3, &lt;strong&gt;IE10&lt;/strong&gt; (which you can download with Windows &amp;ldquo;8&amp;rdquo; Developer Preview &lt;a href="http://msdn.microsoft.com/en-us/windows/apps/br229516" target="_blank"&gt;here&lt;/a&gt;) supports CSS3 Transitions:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5228.image_5F00_02E9A817.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/7360.image_5F00_thumb_5F00_79AD6CD5.png" alt="image" width="826" height="298" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p align="center"&gt;This report was produced by &lt;a href="http://caniuse.com/#search=CSS3 transitions"&gt;http://caniuse.com/#search=CSS3 transitions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Of course, as the specification is not finished (&lt;em&gt;working draft&lt;/em&gt;), you must use vendor&amp;rsquo;s prefixes such as &amp;ndash;ms-, &amp;ndash;moz-, &amp;ndash;webkit-, &amp;ndash;o-.&lt;/p&gt;
&lt;p&gt;We can obviously see that we need to provide a &lt;strong&gt;transparent solution&lt;/strong&gt; in order to address all kind of browsers. The best way will be to develop an API that can detect the support of CSS3 transitions. If the browser doesn&amp;rsquo;t support the feature, we will fallback to some JavaScript code.&lt;/p&gt;
&lt;p&gt;It is important to support a fallback method if you rely on transitions for websites functionalities. If you don&amp;rsquo;t want to do that, you should consider using transitions only for design enhancements&lt;strong&gt;.&lt;/strong&gt; In this case, the site will still work but only supported browsers will deliver the full experience. We speak here of &amp;ldquo;&lt;strong&gt;progressive enhancements&lt;/strong&gt;&amp;rdquo; as the more powerfull the browser is, the more features he gets.&lt;/p&gt;
&lt;h1&gt;&lt;a id="c01"&gt;Transitions without CSS3 Transitions&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;So to be able to support a fallback to CSS3 Transitions, we will develop a small toolkit to provide transitions by code.&lt;/p&gt;
&lt;p&gt;First of all, we will create a container object for our namespace:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:250d11a9-fabd-4136-a85e-34e10fa835c3" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: 1px solid #000080; color: #000000; font-family: 'Courier New', courier, monospace; font-size: 10pt;"&gt;
&lt;div style="background: #ffffff; overflow: auto; max-height: 300px;"&gt;&lt;ol style="background: #ffffff; margin: 0px; padding: 0px 0px 0px 5px;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; TRANSITIONSHELPER = TRANSITIONSHELPER || {};&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;TRANSITIONSHELPER.tickIntervalID = 0;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;TRANSITIONSHELPER.easingFunctions = {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; linear:0,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ease:1,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; easein:2,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; easeout:3,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; easeinout:4,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; custom:5&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;};&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;TRANSITIONSHELPER.currentTransitions = [];&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To support the same level of easing functions, we must declare an &amp;ldquo;enum&amp;rdquo; with all required fields.&lt;/p&gt;
&lt;p&gt;The toolkit is based on a function which is called every 17ms (to achieve animations at 60 fps). The function will enumerate through a collection of active transitions. For each transition the code will evaluate the next value given the current value and the target value.&lt;/p&gt;
&lt;p&gt;We will need some &lt;strong&gt;handy&lt;/strong&gt; functions to extract value of properties and units used:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5835a175-97d0-4d2d-8aa3-b92d04c3c983" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: 1px solid #000080; color: #000000; font-family: 'Courier New', courier, monospace; font-size: 10pt;"&gt;
&lt;div style="background: #ffffff; overflow: auto; max-height: 500px;"&gt;&lt;ol style="background: #ffffff; margin: 0px; padding: 0px 0px 0px 5px;"&gt;
&lt;li&gt;TRANSITIONSHELPER.extractValue = &lt;span style="color: #0000ff;"&gt;function&lt;/span&gt; (string) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;try&lt;/span&gt; {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; result = parseFloat(string);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (isNaN(result)) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; 0;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; result;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="color: #0000ff;"&gt;catch&lt;/span&gt; (e) {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; 0;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/li&gt;
&lt;li&gt;};&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;TRANSITIONSHELPER.extractUnit = &lt;span style="color: #0000ff;"&gt;function&lt;/span&gt; (string) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #006400;"&gt;// if value is empty we assume that it is px&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (string == &lt;span style="color: #800000;"&gt;""&lt;/span&gt;) {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #800000;"&gt;"px"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; value = TRANSITIONSHELPER.extractValue(string);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; unit = string.replace(value, &lt;span style="color: #800000;"&gt;""&lt;/span&gt;);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; unit;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;};&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The main function will process active transitions and will call the cubic bezier function to evaluate current values:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dfbda549-61a6-4030-aa72-23db93c5d895" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 500px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;TRANSITIONSHELPER.tick = &lt;span style="color: #0000ff;"&gt;function&lt;/span&gt; () {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Processing transitions&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; index = 0; index &amp;lt; TRANSITIONSHELPER.currentTransitions.length; index++) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; transition = TRANSITIONSHELPER.currentTransitions[index];&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// compute new value&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; currentDate = (&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Date).getTime();&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; diff = currentDate - transition.startDate;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; step = diff / transition.duration;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; offset = 1;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Timing function&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;switch&lt;/span&gt; (transition.ease) {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;case&lt;/span&gt; TRANSITIONSHELPER.easingFunctions.linear:&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;offset = TRANSITIONSHELPER.computeCubicBezierCurveInterpolation(step, 0, 0, 1.0, 1.0);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;break&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;case&lt;/span&gt; TRANSITIONSHELPER.easingFunctions.ease:&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;offset = TRANSITIONSHELPER.computeCubicBezierCurveInterpolation(step, 0.25, 0.1, 0.25, 1.0);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;break&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;case&lt;/span&gt; TRANSITIONSHELPER.easingFunctions.easein:&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;offset = TRANSITIONSHELPER.computeCubicBezierCurveInterpolation(step, 0.42, 0, 1.0, 1.0);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;break&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;case&lt;/span&gt; TRANSITIONSHELPER.easingFunctions.easeout:&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;offset = TRANSITIONSHELPER.computeCubicBezierCurveInterpolation(step, 0, 0, 0.58, 1.0);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;break&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;case&lt;/span&gt; TRANSITIONSHELPER.easingFunctions.easeinout:&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;offset = TRANSITIONSHELPER.computeCubicBezierCurveInterpolation(step, 0.42, 0, 0.58, 1.0);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;break&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;case&lt;/span&gt; TRANSITIONSHELPER.easingFunctions.custom:&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;offset = TRANSITIONSHELPER.computeCubicBezierCurveInterpolation(step, transition.customEaseP1X, transition.customEaseP1Y, transition.customEaseP2X, transition.customEaseP2Y);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;break&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;offset *= (transition.finalValue - transition.originalValue);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; unit = TRANSITIONSHELPER.extractUnit(transition.target.style[transition.property]);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; currentValue = transition.originalValue + offset;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;transition.currentDate = currentDate;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Dead transition?&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (currentDate &amp;gt;= transition.startDate + transition.duration) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentValue = transition.finalValue; &lt;span style="color: #006400;"&gt;// Clamping&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TRANSITIONSHELPER.currentTransitions.splice(index, 1); &lt;span style="color: #006400;"&gt;// Removing transition&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;index--;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Completion event&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (transition.onCompletion) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;transition.onCompletion({propertyName:transition.property, elapsedTime:transition.duration});&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Affect it&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;transition.target.style[transition.property] = currentValue + unit;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;};&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The current version of the toolkit only supports numeric values but if you want to animate complex values (such as color) you just have to decompose them to simple values.&lt;/p&gt;
&lt;p&gt;Registering a transition in the system will be done using the following code:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f43904ca-11e4-4bd6-b5da-f76a09f03056" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"&gt;
&lt;div style="background: #fff; max-height: 500px; overflow: auto;"&gt;&lt;ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"&gt;
&lt;li&gt;TRANSITIONSHELPER.transition = &lt;span style="color: #0000ff;"&gt;function&lt;/span&gt; (target, property, newValue, duration, ease, customEaseP1X, customEaseP1Y, customEaseP2X, customEaseP2Y, onCompletion) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Create a new transition&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; transition = {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;target: target,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;property: property,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;finalValue: newValue,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;originalValue: TRANSITIONSHELPER.extractValue(target.style[property]),&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;duration: duration,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;startDate: (&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Date).getTime(),&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentDate: (&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Date).getTime(),&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ease:ease,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;customEaseP1X:customEaseP1X,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;customEaseP2X:customEaseP2X,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;customEaseP1Y: customEaseP1Y,&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;customEaseP2Y: customEaseP2Y,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onCompletion: onCompletion&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Launching the tick service if required&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (TRANSITIONSHELPER.tickIntervalID == 0) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TRANSITIONSHELPER.tickIntervalID = setInterval(TRANSITIONSHELPER.tick, 17);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Remove previous transitions on same property and target&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; index = 0; index &amp;lt; TRANSITIONSHELPER.currentTransitions.length; index++) {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;var&lt;/span&gt; temp = TRANSITIONSHELPER.currentTransitions[index];&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (temp.target === transition.target &amp;amp;&amp;amp; temp.property === transition.property) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TRANSITIONSHELPER.currentTransitions.splice(index, 1);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;index--;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #006400;"&gt;// Register&lt;/span&gt;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (transition.originalValue != transition.finalValue) {&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TRANSITIONSHELPER.currentTransitions.push(transition);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li&gt;};&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &amp;ldquo;&lt;em&gt;tick&lt;/em&gt;&amp;rdquo; function is launched when the first transition is activated.&lt;/p&gt;
&lt;p&gt;Finally you just have to use &lt;a href="http://www.modernizr.com/" target="_blank"&gt;modernizr&lt;/a&gt; to define if CSS3 Transitions is supported by the current browser. If not, you can &lt;strong&gt;fallback&lt;/strong&gt; to our toolkit.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The code for the &lt;em&gt;TransitionsHelper&lt;/em&gt; can be downloaded here: &lt;a href="http://www.catuhe.com/msdn/transitions/transitionshelper.js"&gt;http://www.catuhe.com/msdn/transitions/transitionshelper.js&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For example, in my puzzle game, the following code is used to animate the cells:&lt;/p&gt;
&lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:60ee8874-2159-4326-b0d2-8ed266fd94dd" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"&gt;
&lt;div style="border: 1px solid #000080; color: #000000; font-family: 'Courier New', courier, monospace; font-size: 10pt;"&gt;
&lt;div style="background: #ffffff; overflow: auto; max-height: 500px;"&gt;&lt;ol style="background: #ffffff; margin: 0px; padding: 0px 0px 0px 5px;"&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (!PUZZLE.isTransitionsSupported) {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRANSITIONSHELPER.transition(block.div, &lt;span style="color: #800000;"&gt;"top"&lt;/span&gt;, block.x * totalSize + offset, 500, TRANSITIONSHELPER.easingFunctions.ease);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRANSITIONSHELPER.transition(block.div, &lt;span style="color: #800000;"&gt;"left"&lt;/span&gt;, block.y * totalSize + offset, 500, TRANSITIONSHELPER.easingFunctions.ease);&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0000ff;"&gt;else&lt;/span&gt; {&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; block.div.style.top = (block.x * totalSize + offset) + &lt;span style="color: #800000;"&gt;"px"&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; block.div.style.left = (block.y * totalSize + offset) + &lt;span style="color: #800000;"&gt;"px"&lt;/span&gt;;&lt;/li&gt;
&lt;li style="background: #f3f3f3;"&gt;}&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;We can note that I could use&lt;strong&gt; another way&lt;/strong&gt; to animate my cells when CSS3 transitions are supported: I could have defined a collection of CSS3 classes with predefined left and top values (one for each cell) to affect them to right cells.&lt;/p&gt;
&lt;p&gt;Some frameworks and toolkits already exist to support software transitions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;jQuery.transition.js&lt;/em&gt;: &lt;a title="http://louisremi.github.com/jquery.transition.js/test/index.html" href="http://louisremi.github.com/jquery.transition.js/test/index.html"&gt;http://louisremi.github.com/jquery.transition.js/test/index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;jQUery-Animate-Enhanced:&lt;/em&gt; &lt;a title="https://github.com/benbarnett/jQuery-Animate-Enhanced" href="https://github.com/benbarnett/jQuery-Animate-Enhanced"&gt;https://github.com/benbarnett/jQuery-Animate-Enhanced&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By the way, you can also use the old good &lt;em&gt;animate()&lt;/em&gt; method of jQuery.&lt;/p&gt;
&lt;h1&gt;&lt;a id="c04"&gt;Conclusion&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;As we saw, CSS3 Transitions is a really &lt;strong&gt;easy&lt;/strong&gt; way to add animations to your project. You can produce a more &lt;strong&gt;reactive&lt;/strong&gt; application just by using some transitions when you want to change values.&lt;/p&gt;
&lt;p&gt;By the way, there are two solutions if you want to implement a JavaScript fallback:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can do &lt;strong&gt;all&lt;/strong&gt; in the JavaScript side and if you detect the support of CSS3 transitions, you will inject CSS3 declarations in the page.&lt;/li&gt;
&lt;li&gt;Or you can use standard way (using true CSS3 declarations in the CSS files) and just detect the need of fallback in JavaScript. For me, it is the better option as the fallback must be an option and not the main subject. In a near future, all browsers will support CSS3 Transitions and in this case you will just have to remove your fallback code. Furthermore, it is a better way to let all the CSS under the control of the &lt;strong&gt;creative&lt;/strong&gt; team and not in the code part.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;a id="c05"&gt;Going further&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Blog about CSS3 Animations by David Rousset: &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx"&gt;http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;CSS3 Transitions specifications: &lt;a title="http://www.w3.org/TR/css3-transitions/" href="http://www.w3.org/TR/css3-transitions/"&gt;http://www.w3.org/TR/css3-transitions/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;IE Test Drive on CSS3 transitions: &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_transitions.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_transitions.htm"&gt;http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_transitions.htm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Others useful posts:&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a title="http://addyosmani.com/blog/css3transitions-jquery/" href="http://addyosmani.com/blog/css3transitions-jquery/"&gt;http://addyosmani.com/blog/css3transitions-jquery/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title="http://css3.bradshawenterprises.com/" href="http://css3.bradshawenterprises.com/"&gt;http://css3.bradshawenterprises.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title="http://webdesignerwall.com/trends/47-amazing-css3-animation-demos" href="http://webdesignerwall.com/trends/47-amazing-css3-animation-demos"&gt;http://webdesignerwall.com/trends/47-amazing-css3-animation-demos&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;script type="text/javascript"&gt;// &lt;![CDATA[
	$(function() {
		// run the currently selected effect
		function runEffect(target) {
			// get effect type from 
			var selectedEffect = "clip";
			
			var options = {};

			// run the effect
			target.toggle(500 );
		};
		
		$("#properties").hide();
		$("#types").hide();

		// set effect from select menu value
		$( "#propertiesLink" ).click(function() {
			runEffect($("#properties"));
			return false;
		});

		$( "#typesLink" ).click(function() {
			runEffect($("#types"));
			return false;
		});
	});
// ]]&gt;&lt;/script&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10232157" width="1" height="1"&gt;</content><author><name>David Catuhe</name><uri>http://blogs.msdn.com/david.catuhe_4000_live.fr/ProfileUrlRedirect.ashx</uri></author><category term="HTML5" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML5/" /><category term="HTML 5" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML+5/" /><category term="Javascript" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/" /><category term="CSS3" scheme="http://blogs.msdn.com/b/eternalcoding/archive/tags/CSS3/" /></entry></feed>