<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>MSDN Answers</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/msdn_answers/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/msdn_answers/feed.xml</link>
    <description>This blog is an outlet for MSDN writers to answer important developer questions as they arise.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:23:36 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Running Cordova Apps on Windows and Windows Phone 8.1 using Ionic, AngularJS, and other Frameworks</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/running-cordova-apps-on-windows-and-windows-phone-8-1-using-ionic-angularjs-and-other-frameworks</link>
      <pubDate>Tue, 10 Feb 2015 10:37:00 GMT</pubDate>
      <dc:creator><![CDATA[Mike Jones (CSI)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2015/02/10/running-cordova-apps-on-windows-and-windows-phone-8-1-using-ionic-angularjs-and-other-frameworks/</guid>
      <description><![CDATA[I just posted a version of the Ionic SideMenu Starter template for Cordova that is available on...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: Calibri;">I just posted a version of the <a href="https://code.msdn.microsoft.com/Ionic-SideMenu-Starter-8e905eb5">Ionic SideMenu Starter template</a> for Cordova that is available on github. This version of the template is a project built with <a href="https://www.visualstudio.com/en-us/explore/cordova-vs.aspx">Visual Studio Tools for Apache Cordova</a>. After struggling through a couple of issues to get everything working right, I thought I'd write a short post to help others who are trying to get started with Cordova when using some third party frameworks, mainly for Windows and Windows Phone 8.1 targets.</span></p>
<p><span style="font-family: Calibri;">The fixes described here may or may not apply to other third party frameworks (besides Ionic, AngularJS, and WinJS), but they are probably a good place to start if you are running into issues.</span></p>
<p><span style="font-family: Calibri;">The issues I've seen involve the following:</span></p>
<ul>
<li>App fails to load correctly or CSS is not applied</li>
<li>Failure of partial pages to load in multi-page apps</li>
<li>Expired certificate error</li>
</ul>
<p><span style="font-family: Calibri;">I expect some of these issues to be resolved shortly (e.g., the certificate issue), but community samples in particular are not likely to include these fixes soon.</span></p>
<h2><span style="font-family: Calibri;">Update the Shim</span></h2>
<p><span style="font-family: Calibri;">When you target Windows and Windows Phone 8.1 from a Cordova app, you may need to use the JavaScript Dynamic Content shim to enable support for some third party libraries, like Ionic, as a workaround for code that Windows flags as unsafe. In fact, the shim is included in the sample apps and the Blank App template. However, you will need to get an <a href="https://github.com/MsopenTech/winstore-jscompat">updated version</a> of the shim and copy the code into winstore-jscompat.js, or your app may not work correctly. In the Ionic sample I tested, the older version of the shim was dynamically emitting &lt;head&gt; and &lt;a&gt; elements that prevented Ionic CSS from being applied. (In addition, this issue prevents the current AngularJS ToDoList sample app from working on Windows 8.1**.)</span></p>
<p><span style="font-family: Calibri;">**Note: If you want to target Windows Phone 8.1 (recommended) using the ToDoList samples to get started, you will need to update the app as a CTP3 project.</span></p>
<h2><span style="font-family: Calibri;">Fix URL Prefixes (multi-page AngularJS apps)</span></h2>
<p><span style="font-family: Calibri;">Also, when you are using the AngularJS routing module (Ionic starter templates often use this module as well), you may need to include a call to <a href="https://docs.angularjs.org/api/ng/provider/$compileProvider#!">aHrefSanitizationWhitelist</a>. Typically, you include this in app.js or wherever you are calling your module configuration code:</span></p>
<p><span style="font-family: 'courier new', courier;"><span style="color: black;">&nbsp;&nbsp;&nbsp; $compileProvider.aHrefSanitizationWhitelist(</span><span style="color: maroon;">/^\s*(https?|ftp|mailto|file|ghttps?|ms-appx|x-wmapp0):/</span><span style="color: black;">);</span></span></p>
<p><span style="font-family: 'courier new', courier;"><span style="color: black;">&nbsp;&nbsp;&nbsp; $compileProvider.imgSrcSanitizationWhitelist(</span><span style="color: maroon;">/^\s*(https?|ftp|file|ms-appx|x-wmapp0):|data:image\//</span><span style="color: black;">);</span></span></p>
<p><span style="font-family: Calibri;">If you don't include this code, your links may be flagged as unsafe by AngularJS, and partial pages may not load (On Windows, you may see a prompt asking whether to look for an app on the Store). For one example of using this code, see the <a href="https://code.msdn.microsoft.com/Ionic-SideMenu-Starter-8e905eb5">Ionic SideMenu Starter template</a>.</span></p>
<h2><span style="font-family: Calibri;">Update your Windows Certificate</span></h2>
<p><span style="font-family: Calibri;">If you start with the Blank App Cordova template in Visual Studio (or a community sample), you will also run into a Cordova bug caused by an expired certificate for Windows and Windows Phone 8.1. This bug is documented <a href="https://msopentech.com/blog/2014/11/11/cordova-certificate-issue-were-working-on-it/">here</a> and the fix is to include&nbsp;the provided temporary certificate either in /res/native/windows (Visual Studio 2015) or in /res/cert/windows8 (Visual Studio 2013 Update 4).</span></p>
<h2><span style="font-family: Calibri;">WinJS Compatibility Bug</span></h2>
<p><span style="font-family: Calibri;">Lastly, if you are using WinJS and some third party libraries like jQuery, you may run into <a href="https://github.com/winjs/winjs/issues/718">this navigation issue</a>. The fix has been checked into WinJS, but at present you will need to build your own version of WinJS to get the updated versions of ui.min.js and base.min.js.</span></p>
<p><span style="font-family: Calibri;">Hopefully, these tips will help you get up and running!</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Porting a Windows Store App using HTML to Cordova</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/porting-a-windows-store-app-using-html-to-cordova</link>
      <pubDate>Tue, 26 Aug 2014 14:46:00 GMT</pubDate>
      <dc:creator><![CDATA[Mike Jones (CSI)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2014/08/26/porting-a-windows-store-app-using-html-to-cordova/</guid>
      <description><![CDATA[Visual Studio recently released a preview for Multi-Device Hybrid Apps, that allows you to create...]]></description>
      <content:encoded><![CDATA[<p>Visual Studio recently released a preview for Multi-Device Hybrid Apps, that allows you to <a href="https://msdn.microsoft.com/en-us/library/dn771545.aspx">create Cordova apps</a> in Visual Studio. Cordova is a cross-platform API and build toolset that provides access to native device APIs using HTML, CSS, and JavaScript. If you've already created a Windows Store app using HTML and JavaScript, you can port your app to Android and iOS by using Cordova. The easiest way to move the project to Cordova is to create a Multi-Device Hybrid App in Visual Studio using the open source version of WinJS (Windows Library for JavaScript).</p>
<p>Out of the box, the <a href="https://msdn.microsoft.com/en-us/vstudio/dn722381.aspx">Multi-Device Hybrid Apps extension</a> for Visual Studio includes only the Blank template. I took one of the more popular Windows Store templates, the Navigation App template, and ported it to Cordova. This template is available <a href="https://code.msdn.microsoft.com/WinJS-Navigation-Template-50112ea9">here</a>. In this post, I thought I'd share what I learned in that process.</p>
<p>Before going through the porting process, you can evaluate your app for the likely ease, or difficulty, of making it work in Cordova. Here are some of the main considerations:</p>
<ul>
<li>Are there a lot of calls to Windows Runtime APIs? Cordova in VS supports the WinJS APIs, but native Windows Runtime APIs (Windows.* namespace) won't work in a Cordova app. For app lifecycle code and a few other common events, Cordova has APIs that you can use instead. For other native code, you may need to use a Cordova plugin to replace the native APIs, and code your app using the plugin's interface (JavaScript APIs).</li>
<li>If you need to use a Cordova plugin for access to native APIs (for example, Geolocation or Camera APIs), check whether the feature is supported in a <a href="https://msdn.microsoft.com/library/dn757051.aspx">core plugin</a> or a third-party plugin. Core plugins typically support all the most common target platforms; in third-party plugins, platform support varies. If plugin support is not already available for the native feature, work will be required to create a custom plugin (or to extend an existing plugin) before your app will work in Cordova. Creating a custom plugin will involve writing native code for the platform(s) that you are going to support.</li>
<li>Are you using any third-party frameworks besides WinJS? Some frameworks may have incompatibilities with specific platforms or with Cordova.</li>
</ul>
<p>The main steps involved in porting your app to Cordova:</p>
<ol>
<li>Create your project using a Multi-Device Hybrid App sample app that uses WinJS.</li>
<li>Open it in VS, manually copy over your code, and get rid of any sample code that you don't need.</li>
<li>Update the app lifecycle code to use Cordova events.</li>
<li>Rewrite code that requires the use of a plugin.</li>
<li>Test the CSS in the various emulators. Use the merges folder for platform-specific CSS, if necessary.</li>
<li>Update images in platform resource files.</li>
</ol>
<h2><br />1.&nbsp;Create your project using a Multi-Device Hybrid App sample</h2>
<p>Instead of using the Blank template included with Cordova, start with one of these sample apps; the apps listed here simplify the setup of the open source WinJS. A custom PowerShell script in the project file will automatically download and include WinJS when you build the project.</p>
<ul>
<li><a href="https://code.msdn.microsoft.com/WinJS-Navigation-Template-50112ea9">Cordova Navigation Template</a> (WinJS). This is a port of the Windows Store Navigation App template, and provides a simple multi-page app with page animations and Back button support. It includes the Windows Store navigator.js file.</li>
<li><a href="https://code.msdn.microsoft.com/WinJS-TODO-Sample-for-17295485">ToDoList sample</a> using WinJS. This sample provides local storage using HTML5 Web Storage, cloud-storage using Azure Mobile Services, and geolocation using Bing Maps. Note that this sample uses TypeScript out of the box.</li>
</ul>
<h2>2. Manually copy your HTML, JavaScript, and CSS code, and get rid of sample code you don't need</h2>
<p>No shortcuts here, but it's not hard for smaller apps. Cordova uses an index.html file instead of default.html. If you use the out-of-the-box Cordova project structure, you will naturally need to update script and internal URI references;&nbsp; for example, in calls to <strong>WinJS.Navigation.navigate</strong>.</p>
<h2><br />3.&nbsp;Update the app lifecycle code</h2>
<p>The app lifecycle code in a Windows Store app likely includes one or more calls to Windows Runtime APIs. You need to replace these with Cordova APIs, such as the <a href="https://cordova.apache.org/docs/en/3.5.0/cordova_events_events.md.html#Events">deviceready</a> event handler. Here is an example of app lifecycle code from the Cordova Navigation Template. This code eliminates the need to call the <strong>Windows.ApplicationModel.Activation</strong> API.</p>
<p><br /><span style="font-family: courier new,courier;">(function () {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; "use strict";</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; var app = WinJS.Application;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; var nav = WinJS.Navigation;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; var sched = WinJS.Utilities.Scheduler;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; var ui = WinJS.UI;</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; document.addEventListener("deviceready", onReady, false);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; document.addEventListener("resume", onResume, false);</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; function onReady() {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Handle the deviceready event.</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; initialize();</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; function onResume() {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Handle the resume event</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; function initialize() {</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nav.history = app.sessionState.history || {};</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nav.history.current.initialPlaceholder = true;</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Optimize the load of the application and <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // while the splash screen is shown, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: courier new,courier;">// execute high priority scheduled work.</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ui.disableAnimations();</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var p = ui.processAll().then(function () {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return nav.navigate(nav.location || Application.navigator.home, nav.state);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }).then(function () {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return sched.requestDrain(sched.Priority.aboveNormal + 1);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }).then(function () {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ui.enableAnimations();</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-family: courier new,courier;">})();</span></p>
<h2><br />4.&nbsp;Rewrite code that requires use of a plugin</h2>
<p>If your app requires extensive use of one or more plugins, this step will likely involve the most work. If it requires only plugins that already work on all target platforms, especially the core plugins, comparatively less work will be required.</p>
<p>To support certain types of changes you made to the package.manifest file in the new app (before you ported it), you may have to use a plugin.<br />Cordova provides some handy APIs for a few events such as <strong>backbutton</strong>. If you can use these events instead of native APIs, you don't need to use a plugin. For more info, see <a href="https://cordova.apache.org/docs/en/3.3.0/cordova_events_events.md.html#Events">Events</a>.</p>
<h2><br />5.&nbsp;Test and update the CSS</h2>
<p>You're in the web developer world now! You will need to test your app on the different platforms and deal with browser differences in CSS implementations. Fortunately, WinJS should handle most of this, but there are exceptions. For example, Webkit-based browsers (Android, iOS) don't currently support the CSS3 grid layout, so you may need to use a flexbox in your app instead.</p>
<p>The Ripple Emulator will provide quick and easy testing of layout and CSS on Android and iOS. But, of course, to really verify your app you will need to do testing on platform emulators and devices.</p>
<p>The best practice for handling differences in display size (and orientation changes) is to use<strong> @media</strong> rules. For example, the following CSS applies to display sizes &lt;500 px in width. Here, you override margin values for the .fragment header CSS selector.</p>
<p><br /><span style="font-family: courier new,courier;">@media (max-width:499px) {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; .fragment header[role=banner] {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin-left: 15px;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin-right: 30px;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="font-family: courier new,courier;">}</span></p>
<p>If necessary, use the merges folder to provide platform-specific CSS values. Cordova recommends using an overrides.css file for this purpose. When you use overrides, you should include an empty overrides.css in the project's css folder.</p>
<p>WinJS provides ui-dark.css and ui-light.css as style templates. You will need to decide which one provides the look you want in your app and whether you want the app to look the same on all platforms. If not, you will need to decide how much extra effort you want to invest to make the app look like a native app on all target platforms.</p>
<h2><br />6.&nbsp;Update images in platform resource files</h2>
<p>Android and iOS include device-specific files for the splashscreen and icons. The sample apps include these files, but the art will need to be updated for your app.</p>
<h2><br />Finally -- Test, package, and publish</h2>
<p><br />Packaging and publishing is platform-specific. For more info, see the <a href="https://msdn.microsoft.com/library/dn771545.aspx">documentation</a>.</p>
<p>VS for Multi-Device Hybrid Apps doesn't&nbsp;support debugging Windows Phone targets in the current release (but that is coming, I'm told). So, if you're porting from a Windows Store app, you may choose to test, package, and publish for Windows Phone using your native Windows Store project (requires Windows 8.1 for phone support).</p>]]></content:encoded>
    </item>
    <item>
      <title>Quick reference guide for .NET regular expressions</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/quick-reference-guide-for-net-regular-expressions</link>
      <pubDate>Fri, 06 Jun 2014 17:13:11 GMT</pubDate>
      <dc:creator><![CDATA[Cheryl Simmons]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2014/06/06/quick-reference-guide-for-net-regular-expressions/</guid>
      <description><![CDATA[I don't know about you, but I use regular expressions just enough to be dangerous.  By that I mean...]]></description>
      <content:encoded><![CDATA[<p>I don't know about you, but I use regular expressions just enough to be dangerous.</p>  <p>By that I mean that I don't use regular expressions very often and so I often get them wrong. When I want to write a complex regex, I find myself consulting the docs extensively and/or using a regex validation tool to figure out how to write the regex I need to get the results I want. </p>  <p>To help me (and developers like me), my teammates put together this handy <a href="https://www.microsoft.com/en-us/download/details.aspx?id=43119">downloadable guide to .NET regular expressions</a>. You can download the guide as a .pdf or a .doc and it’s in brochure format. The idea is that you can either save the file to your computer, or if you want to print it out, you can fold it into a neat brochure. You can see a snippet of the brochure below:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/0333.image_2F62843B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/0333.image_5F00_2F62843B.png"><img title="image" style="display: inline; background-image: none;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/7288.image_thumb_56309A7B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/7288.image_5F00_thumb_5F00_56309A7B.png" width="421" height="143" /></a></p>  <p>This brochure format is something new we're exploring and we'd love to hear what you think. However, we mostly hope you will find this useful when you are writing regular expressions.</p>]]></content:encoded>
    </item>
    <item>
      <title>Universal apps - create JavaScript apps for Windows and Windows Phone</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/universal-apps-create-javascript-apps-for-windows-and-windows-phone</link>
      <pubDate>Thu, 03 Apr 2014 09:10:00 GMT</pubDate>
      <dc:creator><![CDATA[Mike Jones (CSI)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2014/04/03/universal-apps-create-javascript-apps-for-windows-and-windows-phone/</guid>
      <description><![CDATA[At Microsoft's BUILD conference this week, platform and tool supporthas been made available for...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: Calibri; font-size: small;">At Microsoft's BUILD conference this week, platform and tool support<br />has been made available for developers to build "universal apps".<br />Developers can now create a single solution that targets Windows 8.1 and<br />Windows Phone 8.1 using shared code. You can do this using XAML with C#/VB/C++,<br />or by using HTML and JavaScript.</span></p>
<p><span style="font-family: Calibri; font-size: small;">Being a JavaScript enthusiast, and also assigned to the language, I'm most excited<br />about the fact that you can now use HTML and JavaScript for Windows Phone.<br />Cool. Being able to do it in a single VS solution using shared code is gravy.</span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">I ported my JSON Web reader app to a universal app template<br />in Visual Studio 2013 Update 2 (required). This solution targets both Window 8.1<br />and Windows Phone 8.1. You can check out that app here:</span></span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri;"><span style="line-height: 115%; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><span style="font-family: Calibri;"><span style="line-height: 115%; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><a href="https://code.msdn.microsoft.com/JSON-Web-reader-that-uses-f6500b57">JSON Web reader that uses the Hub/Pivot template</a></span></span></span></span></span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">To get Visual Studio 2013 Update 2, which includes the Phone Emulator, and to get general info<br />about universal apps, go here:</span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri;"><span style="line-height: 115%; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><a href="https://msdn.microsoft.com/en-US/windows/dn642498">Building universal apps</a></span></span></span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">To use the Phone Emulator, you need a machine with second level address translation (SLAT). For more info, go here:</span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri;"><span style="line-height: 115%; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><a href="https://msdn.microsoft.com/en-us/library/windowsphone/develop/ff626524(v=vs.105).aspx">Windows Phone Emulator system requirements</a></span></span></span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">For info about the templates, go here:</span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;"><span style="line-height: 115%; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><a href="https://msdn.microsoft.com/en-us/library/windows/apps/hh758331.aspx">JavaScript project templates</a></span></span></li>
<li><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri;"><a href="https://msdn.microsoft.com/en-us/library/windows/apps/hh768232.aspx">C#/VB/C++ project templates</a></span></span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">For info on porting a Windows Store app to the phone<br />(JavaScript emphasis), go here:</span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri;"><span style="line-height: 115%; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn636144.aspx">Porting apps from Windows to Windows Phone</a></span></span></span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">Besides the JSON Web Reader, I've worked on porting various other test samples to Phone. In most cases, I've been pleasantly surprised how easy it is. There are a number of controls that aren't cross-platform, which require more work. But generally, most of the extra work is around coding for different display sizes. Typically, you will use different HTML files for each platform (Phone and Windows have a separate project and app package within the shared solution), but you can use the same JavaScript code. In JavaScript code, you can test whether a feature is available before using it, or call <strong>WinJS.Utilities.isPhone</strong> to check your platform target. See the above links for more details.</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Part III: 3D Chess game using HTML5 and CSS3 now available (Windows Store sample)</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/part-iii-3d-chess-game-using-html5-and-css3-now-available-windows-store-sample</link>
      <pubDate>Wed, 19 Feb 2014 10:40:00 GMT</pubDate>
      <dc:creator><![CDATA[Mike Jones (CSI)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2014/02/19/part-iii-3d-chess-game-using-html5-and-css3-now-available-windows-store-sample/</guid>
      <description><![CDATA[The 3D chess app is a hybrid HTML5 and CSS3 app. The board is animated using CSS3 perspective...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: Calibri; font-size: small;">The 3D chess app is a hybrid HTML5 and CSS3 app. The board is animated using CSS3 perspective transforms and hardware-accelerated rotations. CSS3 animations are also used to add, move, capture, and remove chess pieces from the board. Board rotations render all chess pieces on an HTML5 &lt;canvas&gt; overlay, moving these animations off the UI thread (onto the GPU).</span></p>
<p><span style="font-family: Calibri; font-size: small;">The app uses a combination of 3D and 2D technologies to provide 3D effects without the development cost of creating full 3D models, such as you might use if you are writing WebGL or DirectX apps.</span></p>
<p><span style="font-family: Calibri; font-size: small;">Currently, the app is implemented for Windows Store. There is not much Win8-dependent platform code, however, so I may port it to IE in a update in the near future.</span></p>
<p><span style="font-family: Calibri; font-size: small;"><a href="https://code.msdn.microsoft.com/3D-Chess-game-using-HTML5-695358ea">Check out the sample here</a></span></p>
<p><span style="font-family: Calibri; font-size: x-small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/6404.3Dchess_small.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86/6404.3Dchess_5F00_small.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/6404.3Dchess_small.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86/6404.3Dchess_5F00_small.png" alt="" border="0" /></a></span></p>
<p><span style="font-family: Calibri; font-size: small;">Here is an illustration showing the chessboard in mid-rotation:</span></p>
<h1><span style="font-family: Calibri; font-size: x-small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/3113.3Dchess_rotation_small.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86/3113.3Dchess_5F00_rotation_5F00_small.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/3113.3Dchess_rotation_small.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86/3113.3Dchess_5F00_rotation_5F00_small.png" alt="" border="0" /></a><br />&nbsp;</span><span style="font-family: Calibri; font-size: small;">Goals</span></h1>
<p><span style="font-family: Calibri; font-size: small;">The main goal of this app is to simulate playing on a real chess board against an actual person, in which touch-based interaction with the board &amp; chess pieces is preferable to a mouse and feels natural (though a mouse also works). The more specific goals of this app are to demonstrate:</span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;">3D perspective-transforms and rotations on the chess board. This uses CSS3 for hardware-accelerated 3D animations.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Board rotations using a hybrid of HTML5 and CSS3. During a rotation, the use of HTML5 <strong>&lt;canvas&gt;</strong> overlay for the chess pieces moves expensive calculations off the UI thread (to the GPU). The pieces are animated using tracking points on the transformed coordinate plane (the chess board, which is itself rotated using CSS3).</span></li>
<li><span style="font-family: Calibri; font-size: small;">Adding, moving, capturing, and removing pieces using CSS3.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Use of <strong>requestAnimationFrame</strong> for performance-optimized repaints, also used during board rotations.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Resetting/rescaling of board and pieces for changes in display size.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Row &amp; column detection.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Sound effects (when capturing a piece).</span></li>
<li><span style="font-family: Calibri; font-size: small;">Dynamically updating CSS3 <strong>@keyframes</strong> rules. Importantly, this allows the use of relatively few @keyframes rules to apply to many different pieces with many different values.</span></li>
<li><span style="font-family: Calibri; font-size: small;">Consistent handling of app state to support different game modes (Start/Play, Add/Remove, Spin, Reach-thru).</span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">This app does <strong>NOT</strong> demonstrate<span>:</span></span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;"><span>Big Blue style AI (it's a two-player game).</span></span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;"><span>Possible future enhancements:</span></span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;"><span>Restricting moves of the chess pieces to legal moves (the simulation is closer to a real chess board, in which you can move pieces wherever you want. The simulation does include capturing pieces, however). Since the app already does row and column detection, enforcement of legal moves is a possible future enhancement.</span></span></li>
<li><span style="font-family: Calibri; font-size: small;"><span>A complete set of chess pieces. Unlike the 3D board, the pieces are 2D artwork that simulate 3D, and I just needed enough pieces to demonstrate all the concepts working. The supported pieces include: all black and white pawns, black and white knights, black and white bishops, and a white queen. (Sorry, no rooks and kings!)</span></span></li>
<li><span style="font-family: Calibri; font-size: small;"><span>Enforcement of player turns. I did not implement support for playing on two different screens at the same time, involving a web service. That is an option for extending the app.</span></span></li>
<li><span style="font-family: Calibri; font-size: small;"><span>Running in a browser outside the context of Windows Store. There is very little WinJS (Win8)-dependent code in this app, but I need to do an additional update to make it available as a Web-only app.</span></span></li>
<li><span style="font-family: Calibri; font-size: small;"><span>Maintenance of app state after termination.</span></span></li>
</ul>
<h1><span style="font-family: Calibri; font-size: small;">Links to More Info:</span></h1>
<h1><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri; font-size: small;"><a href="https://code.msdn.microsoft.com/3D-Chess-game-using-HTML5-695358ea">Check out&nbsp;the sample here</a></span></span></h1>
<p><span style="font-family: Calibri; font-size: small;">My other blog posts about the animation technologies (see Part II if you want more an intro to animations):</span></p>
<ul>
<li><span style="font-family: trebuchet ms,geneva; font-size: small;"><a href="https://blogs.msdn.com/b/msdn_answers/archive/2013/11/04/part-i-using-javascript-to-set-keyframes-in-css-animations-windows-store-apps-ie.aspx">Part I: Using JavaScript to set @keyframes in CSS animations</a></span></li>
<li><span style="font-family: trebuchet ms,geneva; font-size: small;"><a href="https://blogs.msdn.com/b/msdn_answers/archive/2013/12/05/part-ii-running-multiple-css3-and-html5-animations-windows-store-ie.aspx">Part II: Running multiple CSS3 and HTML5 animations</a></span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">Tool-related documentation that was helpful:</span></p>
<ul>
<li><span style="font-family: trebuchet ms,geneva;">The HTML UI Responsiveness profiler was a critical tool to test the effect of board rotations on CPU and visual throughput. For that documentation, see <a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn194502.aspx">this</a>&nbsp;topic and the associated <a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn481124.aspx">Walkthrough</a>.</span></li>
<li><span style="font-family: trebuchet ms,geneva;">The DOM Explorer was essential for comparing expected element values with actual element values. For more info, go <a href="https://msdn.microsoft.com/en-us/library/windows/apps/hh441474.aspx">here</a>.</span></li>
<li><span style="font-family: trebuchet ms,geneva;">To check your own app for memory leaks, use the <a href="https://msdn.microsoft.com/en-us/library/windows/apps/jj819176.aspx">JavaScript memory analyzer</a>.</span></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Now available: Weathr for Windows 8.1 (C++, DirectX, &amp; XAML)</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/now-available-weathr-for-windows-8-1-c-directx-xaml</link>
      <pubDate>Mon, 16 Dec 2013 13:53:00 GMT</pubDate>
      <dc:creator><![CDATA[Thomas Petchel []]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2013/12/16/now-available-weathr-for-windows-8-1-c-directx-xaml/</guid>
      <description><![CDATA[Looking to use C++ and DirectX to differentiate your Windows Store app? Check out Weathr for Windows...]]></description>
      <content:encoded><![CDATA[<p>Looking to use C++ and DirectX to differentiate your Windows Store app? Check out <a title="Weathr" href="https://weathr.codeplex.com">Weathr</a> for Windows 8.1!</p>
<p>Here&rsquo;s a 5-minute video tour of what the app does.</p>
<p>&nbsp;</p>
<p>[View:https://www.youtube.com/watch?v=8qZ6X14JzMw]</p>
<p>&nbsp;</p>
<p>This sample shows off tons of C++ and Windows 8.1 goodness, such as how to:</p>
<ul>
<li>combine C++, C++/CX, XAML, and DirectX.</li>
<li>perform work in the background to keep your app running smoothly.</li>
<li>render 3D content from the app on the live tile and other places in the app.</li>
<li>use secondary tiles.</li>
<li>use pixel shaders to create effects that run on both Intel and ARM-based devices.</li>
<li>work with app bars.</li>
<li>work with the <strong>GestureRecognizer</strong>.</li>
<li>use Semantic Zoom.</li>
<li>use the Search contract.</li>
<li>download and cache images for later use.</li>
<li>use the Settings flyout.</li>
<li>create a basic logger to display diagnostic messages on the UI.</li>
</ul>
<p>I'm working to add more detailed info about how the app works in the&nbsp;<a title="Documentation" href="https://weathr.codeplex.com/documentation">Documentation</a> area. Be sure to check back for the latest updates.&nbsp;</p>
<p>There&rsquo;s also&nbsp;plenty of opportunity to improve the app and add features. Check out the <a title="Issues" href="https://weathr.codeplex.com/workitem/list/basic">Issues</a> tab for some starter ideas.</p>
<p>Whether you're an established&nbsp;DirectX programmer or a C# and XAML developer interested in learning&nbsp;how to leverage the power of C++ and&nbsp;DirectX to differentiate your app, I hope you find this project useful. I look forward to hearing your feedback&nbsp;in the <a title="Discussions" href="https://weathr.codeplex.com/discussions">Discussions</a> area.</p>
<p>Happy coding!&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Part II: Running Multiple CSS3 and HTML5 Animations (Windows Store, IE)</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/part-ii-running-multiple-css3-and-html5-animations-windows-store-ie</link>
      <pubDate>Thu, 05 Dec 2013 11:45:00 GMT</pubDate>
      <dc:creator><![CDATA[Mike Jones (CSI)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2013/12/05/part-ii-running-multiple-css3-and-html5-animations-windows-store-ie/</guid>
      <description><![CDATA[In part I of my exploration of CSS3 for building a casual game, I talked about dynamicallysetting...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: Calibri; font-size: small;">In part I of my exploration of CSS3 for building a casual game, I talked about <a href="https://blogs.msdn.com/b/msdn_answers/archive/2013/11/04/part-i-using-javascript-to-set-keyframes-in-css-animations-windows-store-apps-ie.aspx">dynamically<br />setting the @keyframes rule</a> using JavaScript. In this, more introductory, post, I'll talk about some of the options for running animations, and provide some tips for starting animations and running multiple animations at the same time.</span></p>
<p><span style="font-family: Calibri; font-size: small;">The game I'm working on is a board game with a few 3D elements and (mostly) 2D elements that mimic 3D. I decided to implement the game using CSS3 transforms. In addition to CSS3, I also used the animation timing function, <strong>requestAnimationFrame</strong>, which is associated with the HTML5 specs. At the moment, I'm rendering one set of 2D game piece elements in a parent DIV element, which overlays the game board, but after I finish code optimization and performance testing, I may move the overlay containing the game pieces to an HTML5 <a href="https://msdn.microsoft.com/en-us/library/ie/ff975062(v=vs.85).aspx">&lt;canvas&gt;</a>&nbsp;object.</span></p>
<p><span style="font-family: Calibri; font-size: small;"><strong>Updated info</strong>, 2/19/2014: <a title="Download the completed sample" href="https://code.msdn.microsoft.com/3D-Chess-game-using-HTML5-695358ea">Check out&nbsp;the completed sample (Windows Store version)</a></span></p>
<p><span style="font-family: Calibri; font-size: small;">When I started coding the animated components, I tried to think about user experience (UX) first before choosing a methodology for a particular animation. For UX, the main considerations were:</span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;">Should touch/click or button click invoke an animation, or will the app initiate the animation itself?</span></li>
<li><span style="font-family: Calibri; font-size: small;">Should the animation complete every time it runs, or can it be canceled?</span></li>
<li><span style="font-family: Calibri; font-size: small;">Does the animation need to support different values for multiple DOM elements? </span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">In your own coding, the answers to these questions can help you decide whether to start a particular animation using CSS pseudo-classes (<strong>focus</strong>, <strong>hover</strong>), by simply resetting animations in your JavaScript code, or by using <strong>requestAnimationFrame</strong>.</span></p>
<h1><span style="font-size: small;"><strong><span style="font-family: Calibri;">A few words about animation technologies</span></strong></span></h1>
<p><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri;">CSS3 allows you to perform animations using DOM element properties. If you use HTML5 or <a href="https://msdn.microsoft.com/en-us/library/ie/bg182648(v=vs.85).aspx">WebGL</a></span><span style="font-family: Calibri;"> instead, your app will likely involve more development time but will&nbsp;typically result in the best performance. If your app requires lots of&nbsp;complex computations for positioning elements, plan on using HTML5 <a href="https://msdn.microsoft.com/en-us/library/ie/ff975062(v=vs.85).aspx">&lt;canvas&gt;</a>&nbsp;or <a href="https://msdn.microsoft.com/en-us/library/ie/bg182648(v=vs.85).aspx">WebGL</a>. In that scenario, you may want to skip to the last section, "Using requestAnimationFrame to start an animation."</span></span></p>
<p><span style="font-family: Calibri; font-size: small;">If your animations follow predictable patterns, CSS3 may work great, and these animations will get hardware-accelerated. In addition, if you are moving lots of DOM elements around the screen using <strong>left </strong>and <strong>top</strong> CSS style properties (not CSS3), you will need to keep a close eye on perf.</span></p>
<h1><span style="font-size: small;"><strong><span style="font-family: Calibri;">Using focus and hover events to start an animation</span></strong></span></h1>
<p><span style="font-family: Calibri; font-size: small;">You can initiate CSS3 animations by implementing pseudo-classes such as <strong>focus</strong> and<strong> hover </strong>on specific elements. <strong>hover</strong> isn't much use in a touch-centric app, so after a few tests I stopped using it. The <strong>focus</strong> event was more intriguing. <strong></strong></span></p>
<p><span style="font-family: Calibri; font-size: small;">To use <strong>focus</strong> (or <strong>hover</strong>), create an animation in your CSS. The following example shows a rotate animation around the Z-axis.</span></p>
<p><span style="font-family: Courier New; font-size: small;">&nbsp; @keyframes rotate {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Courier New; font-size: small;">from {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Courier New; font-size: small;">transform: rotateZ(0deg);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Courier New; font-size: small;">}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Courier New; font-size: small;">to {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Courier New; font-size: small;">transform: rotateZ(180deg);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Courier New; font-size: small;">}<br />&nbsp; </span><span style="font-family: Courier New; font-size: small;">}</span></p>
<p><span style="font-family: Calibri; font-size: small;">To use this animation, set the animation properties on the associated DOM element in your CSS or in your JavaScript code. Here's an example of CSS:</span></p>
<p><span style="font-family: courier new,courier; font-size: small;">&nbsp;&nbsp;animation-duration: 6s;<br />&nbsp;&nbsp;animation-fill-mode: forwards;<br />&nbsp;&nbsp;animation-timing-function: ease-in-out</span></p>
<p><span style="font-family: Calibri; font-size: small;">Then include the <strong>hover</strong> or <strong>focus</strong> event selector and the <strong>animation-name </strong>property. (I've shown both event selectors here.)</span></p>
<p><span style="color: black; font-family: Courier New; font-size: small;">&nbsp; #inner:focus {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; animation-name: rotate;<br />&nbsp; }<br />&nbsp; #outer:hover {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; animation-name: rotate;<br />&nbsp; }</span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">You can let the user start the animation by touch or click, or just call <em>someFocusableElement</em>.focus() </span></span><span style="font-size: small;">in your code.</span></p>
<p><span style="font-family: Calibri; font-size: small;">There are a few UX considerations to manage when using <strong>focus.</strong></span></p>
<ul>
<li><span style="font-family: Calibri; font-size: small;">Your animation gets canceled as soon as something else receives focus.</span></li>
<li><span style="font-family: Calibri; font-size: small;">You may not always want the user to decide which element receives focus.</span></li>
</ul>
<p><span style="font-family: Calibri; font-size: small;">The easiest way to manage these issues is to enable and disable pointer events on different elements. If you start an animation using <strong>focus</strong> and you want it to finish, disable pointer events on the other UI elements until the animation completes.</span></p>
<p><span style="font-family: Calibri; font-size: small;">To disable pointer events on a set of elements:</span></p>
<p><span style="color: black; font-family: courier new,courier; font-size: small;">&nbsp; var children = wrapperElem.children; <br />&nbsp; var len = children.length; <br />&nbsp; for (var i = 0; i &lt; len; i++) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; children[i].style.pointerEvents = "none";<br />&nbsp; }</span></p>
<p><span style="font-family: Calibri; font-size: small;">To re-enable pointer events, use this value:</span></p>
<p><span style="font-family: courier new,courier; font-size: small;">&nbsp; children[i].style.pointerEvents = "visiblePainted";</span></p>
<p><span style="font-family: Calibri; font-size: small;">If you need user-initiated animations but don't want to disable events on the other elements, use handlers for events like <strong>mouseup</strong>, <strong>mousedown</strong>, or<strong> focus</strong> in your code, and then use a different method to start the animation (see the following sections). In this scenario, you will of course need to remove the <strong>focus</strong> rule from your CSS code.</span></p>
<h1><span style="font-size: small;"><strong><span style="font-family: Calibri;">Changing the animation values to start an animation</span></strong></span></h1>
<p><span style="font-family: Calibri; font-size: small;">When you change the animation values for an element, you start the animation. Depending on the new values, this will appear either as a restart or an update. For your animation to appear smooth, the starting CSS3 transform properties (like <strong>translate</strong>, <strong>rotate</strong>, <strong>scale</strong>, and <strong>opacity</strong>) must match the end properties of the previous animation. To incrementally change animation values that are different for each element in a set of DOM elements, you can <a href="https://blogs.msdn.com/b/msdn_answers/archive/2013/11/04/part-i-using-javascript-to-set-keyframes-in-css-animations-windows-store-apps-ie.aspx">dynamically change the @keyframes rule</a>. </span></p>
<p><span style="font-family: Calibri; font-size: small;">A very simple way to control animation using JavaScript is to create two or more <strong>@keyframes </strong>rules for an element. Then, when you want to start a new animation, just change the <strong>animation-name</strong> property from one rule to the other (you&nbsp;first reset duration, etc. in JavaScript).</span></p>
<p><span style="font-family: courier new,courier; font-size: small;">&nbsp;&nbsp;elem.style.animationName = exitPiece;</span></p>
<p><span style="font-family: Calibri; font-size: small;">For example, I use the following rules for game elements in my board game app: enterPiece when a game piece is added, and exitPiece when a game piece is removed. Here is the CSS:</span></p>
<p><span style="font-family: courier new,courier;">&nbsp; @keyframes enterPiece {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transform: translateY(-150px) scale(.5);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opacity: 0;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;transform: translateY(0px) scale(1);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opacity: 1;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-family: courier new,courier;">&nbsp; }</span></p>
<p><span style="font-family: courier new,courier;">&nbsp; @keyframes exitPiece {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transform: translateY(0px) scale(1);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opacity: 1;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transform: translateY(-150px) scale(.5);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;opacity: 0;</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp; </span>}</p>
<p>&nbsp;</p>
<p><span style="font-family: Calibri; font-size: small;">If you want to support additional behavior (for example when a game piece gets captured), you can create additional rules.</span></p>
<h1><span style="font-size: small;"><strong><span style="font-family: Calibri;">Using requestAnimationFrame to start an animation</span></strong></span></h1>
<p><span style="font-family: Calibri; font-size: small;">The performance-optimized <a href="https://ie.microsoft.com/testdrive/Graphics/RequestAnimationFrame/Default.html">requestAnimationFrame</a>&nbsp;function has replaced <strong>setTimeout</strong> and <strong>setInterval</strong> as the function of choice for timer-based animations. The callback function you pass to <strong>requestAnimationFrame </strong>gets called only when the browser is about to repaint the screen, so there are no wasted code cycles.</span></p>
<p><span style="font-size: small;"><strong><span style="font-family: Calibri;"><span style="font-family: Calibri;">requestAnimationFrame</span></span></strong><span style="font-family: Calibri;"><span style="font-family: Calibri;"> is critical for independently adjusting values that need to be different for each member of a set of animated DOM elements. This function is used in loop-based HTML5 <a href="https://msdn.microsoft.com/en-us/library/ie/ff975062(v=vs.85).aspx">&lt;canvas&gt;</a>&nbsp;apps, but you can also use it for simple manipulations of CSS properties like <strong>top</strong> and <strong>left</strong>. (If you want to benefit additionally from hardware acceleration, use <strong>requestAnimationFrame</strong> with HTML5 <a href="https://msdn.microsoft.com/en-us/library/ie/ff975062(v=vs.85).aspx">&lt;canvas&gt;</a>, with <a href="https://msdn.microsoft.com/en-us/library/ie/bg182648(v=vs.85).aspx">WebGL</a></span></span><span style="font-family: Calibri;"><span style="font-family: Calibri;">, or potentially with some CSS3 properties values set in JavaScript.)</span></span><strong><span style="font-family: Calibri;"><span style="font-family: Calibri;"><br /><br /></span></span></strong></span><span style="font-size: small;"><strong><span style="font-family: Calibri;">Note</span></strong><span style="font-family: Calibri;">: If you are resetting lots of DOM elements using <strong>left </strong>and <strong>top</strong> properties, you will need a tool to help test perf. In Windows Store apps and web apps, use the <a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn194502.aspx">HTML UI Responsiveness profiler</a>. The same profiler is available in F12 tools for IE11. The profiler is easy to use and provides good feedback on CPU utilization and frame rate. If there are perf issues, you may need to switch to a <a href="https://msdn.microsoft.com/en-us/library/ie/ff975062(v=vs.85).aspx">&lt;canvas&gt;</a>&nbsp;implementation.</span></span></p>
<p><span style="font-family: Calibri; font-size: small;">You call <strong>requestAnimationFrame </strong>like this:</span></p>
<p><span style="color: black; font-family: courier new,courier; font-size: small;">&nbsp; var requestId = window.requestAnimationFrame(animFrame);</span></p>
<p><span style="font-family: Calibri; font-size: small;">You must be sure to cancel the animation callback when your animation is complete:</span></p>
<p><span style="color: black; font-family: courier new,courier; font-size: small;">&nbsp; window.cancelAnimationFrame(requestId);</span></p>
<p><span style="font-family: Calibri; font-size: small;">For a loop-based game, you cancel the animation callback when the game ends. In my game, I cancel it in a <strong>setTimeout </strong>timer with a delay value that equals the <strong>animation-duration</strong>.</span></p>
<p><span style="font-family: Calibri; font-size: small;"><strong>Note</strong>: To take action either at the beginning or at the end of an animation, you can use <strong>setTimeout</strong> or events like <strong>MSAnimationStart</strong> and <strong>MSAnimationEnd</strong>.</span></p>
<p><span style="font-family: Calibri; font-size: small;">Here is the essential code for the animation frame callback loop. It includes a recursive call to <strong>requestAnimationFrame</strong>.</span></p>
<p><span style="font-family: courier new,courier;">&nbsp; function animFrame(args) {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Manipulate DOM elements</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; requestId = window.requestAnimationFrame(animFrame);</span><br /><span style="font-family: courier new,courier;">&nbsp; }</span></p>
<p><span style="font-family: Calibri; font-size: small;">Within the animation frame callback function, I get the current <strong>top</strong> and <strong>left </strong>coordinates of my DOM elements using <strong>getBoundingClientRect() </strong>(a very handy API for games, at least for IE and Windows Store, especially when working with a transformed coordinate plane), and then reset those values. The code here is truncated for readability.</span></p>
<p><span style="font-family: courier new,courier;">&nbsp; function animFrame(args) {</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gameObjects.forEach(function(piece) {</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get and manipulate DOM elements, or use cached elements.</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // point may be an element on a transformed coordinate plane,</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // or you might use the current element (piece),</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // depending on your app.</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // <strong>NOTE</strong>: The WinJS call is Windows Store only, so for IE </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // you need to use a different method to get the position</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // of the parent element.</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var pos = WinJS.Utilities.getPosition(point.parentElement);</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var topRect = Math.round(point.getBoundingClientRect().top);</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var leftRect = Math.round(point.getBoundingClientRect().left);</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // pos.top and pos.left are offsets of the parent element.</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; piece.style.top = topRect - pos.top - piece.clientHeight + "px";</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; piece.style.left = leftRect - pos.left + "px";</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; requestId = window.requestAnimationFrame(animFrame);</span><br /><span style="font-family: courier new,courier;">&nbsp; }</span></p>
<p>&nbsp;</p>
<p><span style="font-family: Calibri; font-size: small;">As noted previously, the style and rendering of <strong>top</strong> and <strong>left</strong> values here are not running on the GPU. To to do that, make <a href="https://msdn.microsoft.com/en-us/library/ie/ff975062(v=vs.85).aspx">&lt;canvas&gt;</a>&nbsp;the parent element and use methods available in &lt;canvas&gt; to draw the pieces.</span></p>
<p><span style="font-family: Calibri; font-size: small;">Although you can combine a CCS3 animation with the animations produced in the callback function, you typically just need to run the CSS3 animation once for each DOM element (not once for each frame) in a </span><span style="font-family: Calibri; font-size: small;">complete animation cycle. For example, I combine a CSS3 scale transform with the top/left animations in the previous code, but this code is not contained in the animation callback function. The important aspect </span><span style="font-family: Calibri; font-size: small;">here is the dynamic setting of an <strong>@keyframes</strong> rule to adjust scale individually for each game element. For more information, see my earlier <a href="https://blogs.msdn.com/b/msdn_answers/archive/2013/11/04/part-i-using-javascript-to-set-keyframes-in-css-animations-windows-store-apps-ie.aspx">post</a>.</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;// Get currentScale and targetScale values for each DOM element.</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;cssRuleAdjustScale.deleteRule("0");</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;cssRuleAdjustScale.deleteRule("1");</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;cssRuleAdjustScale.appendRule("0% { transform: " + currentScale + "; }");</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;cssRuleAdjustScale.appendRule("100% { transform: " + targetScale + "; }");</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;piece.style.animationDuration = "5.5s";</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;piece.style.animationName = "adjustScale";</span></p>
<p><span style="font-family: Calibri; font-size: small;">When the app is finished, I'll upload the full sample and post a link here. If you have time to look at it then, please send me some feedback!</span></p>
<div>
<div>
<div>
<p>&nbsp;</p>
</div>
</div>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Part I: Using JavaScript to set @keyframes in CSS animations (Windows Store apps, IE)</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/part-i-using-javascript-to-set-keyframes-in-css-animations-windows-store-apps-ie</link>
      <pubDate>Mon, 04 Nov 2013 15:54:00 GMT</pubDate>
      <dc:creator><![CDATA[Mike Jones (CSI)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2013/11/04/part-i-using-javascript-to-set-keyframes-in-css-animations-windows-store-apps-ie/</guid>
      <description><![CDATA[I'm currently exploring the potential of CSS3 for casual game scenarios. For Windows Store apps in...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: Calibri; font-size: small;">I'm currently exploring the potential of CSS3 for casual game scenarios. For Windows Store apps in particular, CSS3 animations are enticing because you don't have to worry about cross-browser compatibility or APIs that won't work with older versions of Internet Explorer, since everything is IE 10+. Compatibility is one of the main reasons why proponents of Flash for Web apps argue against HTML5/CSS3. But for Windows Store apps, these arguments against HTML5/CSS3 are a non-factor. Instead, if you want to do a game (or just animations) for Windows Store, you need to figure out whether you need CSS3, or HTML5 <a href="https://msdn.microsoft.com/en-us/library/ie/ff975062(v=vs.85).aspx">&lt;canvas&gt;</a>, or maybe the newly supported <a href="https://msdn.microsoft.com/en-us/library/ie/bg182648(v=vs.85).aspx">WebGL</a>&mdash;if we're talking JavaScript (we are)&mdash;for fancier stuff.</span></p>
<p><span style="font-family: Calibri; font-size: small;"><span style="font-family: Calibri; font-size: small;"><strong>Updated info</strong>, 2/19/2014: <a title="Download the completed sample" href="https://code.msdn.microsoft.com/3D-Chess-game-using-HTML5-695358ea">Check out the completed sample (Windows Store version)</a></span></span></p>
<p><span style="font-family: Calibri; font-size: small;">Despite a few hiccups, CSS3 development has been pretty fast&ndash;which is an advantage of the technology vs. using the HTML5 &lt;canvas&gt; (note that &lt;canvas&gt; also has a lot of advantages, especially for games with a large number of independent objects). However, I thought I'd talk about a couple of areas where I got tripped up a bit using CSS3. In this post, I'll talk about the need to dynamically manipulate the <strong>@keyframes </strong>rule using JavaScript.</span></p>
<p><span style="font-family: Calibri; font-size: small;">Basic CSS3 animations are pretty straightforward. You create your DOM elements, declaratively or otherwise, and specify a few animation properties. And then you create a set of one or more <strong>@keyframes</strong><br />rules to handle the actual animations.</span></p>
<p><span style="font-family: Calibri; font-size: small;">Here is some of the CSS code for an HTML element representing a game object. We'll say it's for a DIV element containing an image (<span style="font-family: courier new,courier;">&lt;div id="piece"&gt;&lt;/div&gt;</span>). The <strong>animation-name</strong> rule specifies the <strong>@keyframes </strong>"enterPiece" rule.</span></p>
<p><span style="color: #000000; font-size: small; background-color: #ffffff;"><span style="font-family: Consolas;">&nbsp; #piece</span><span style="font-family: Consolas;"> {</span></span></p>
<p><span style="color: #000000; font-size: small; background-color: #ffffff;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">position</span><span style="font-family: Consolas;">: </span><span style="font-family: Consolas;">absolute</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="color: #000000; font-size: small; background-color: #ffffff;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">animation-duration</span><span style="font-family: Consolas;">: </span><span style="font-family: Consolas;">1.5s</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="color: #000000; font-size: small; background-color: #ffffff;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">animation-fill-mode</span><span style="font-family: Consolas;">: </span><span style="font-family: Consolas;">forwards</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; animation-name: "enterPiece"</span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small; background-color: #ffffff;">&nbsp; }</span></p>
<p><span style="font-family: Calibri; font-size: small;">Here is the CSS code for the <strong>@keyframes </strong>"enterPiece" rule. <strong>@keyframes </strong>allows you to specify beginning/end states and anything in between (such as what the animation should look like when 50% complete). In this example, I just set the beginning/end states.</span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp; @keyframes </span><span style="font-family: Consolas;">enterPiece</span><span style="font-family: Consolas;"> {</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">from</span><span style="font-family: Consolas;"> {</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">transform</span><span style="font-family: Consolas;">: </span><span style="font-family: Consolas;">translateY(-150px) </span><span style="font-family: Consolas;">scale(1)</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">opacity</span><span style="font-family: Consolas;">: </span><span style="font-family: Consolas;">0</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">to</span><span style="font-family: Consolas;"> {</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">transform</span><span style="font-family: Consolas;">: </span><span style="font-family: Consolas;">translateY(0px) </span><span style="font-family: Consolas;">scale(1)</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">opacity</span><span style="font-family: Consolas;">: </span><span style="font-family: Consolas;">1</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp; }</span></p>
<p><span style="font-family: Calibri; font-size: small;">This is all pretty straightforward. The animation for the game object moves the object from a relative starting position of -150px to 0px, and changes the opacity from 0 to 1 while moving it this distance. (I include a <strong>scale</strong> value for informational purposes but I won't be using it&mdash;I'll be setting that value dynamically.)</span></p>
<p><span style="font-family: Calibri; font-size: small;">Here's code to set some of these animation values in JavaScript: In this code, we set the animation duration, fill mode, and the animation name ("enterPiece", again), which specifies the same <strong>@keyframes</strong> code in CSS. In this case, we're doing it for a new element that we're about to add to the DOM.</span></p>
<p><span style="font-size: small;"><span style="font-family: Consolas;">&nbsp; newNode.style.animationDuration = </span><span style="font-family: Consolas;">"1.5s"</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Consolas;">&nbsp; newNode.style.animationFillMode = </span><span style="font-family: Consolas;">"forwards"</span><span style="font-family: Consolas;">;</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Consolas;">&nbsp; newNode.style.animationName = </span><span style="font-family: Consolas;">"enterPiece"</span><span style="font-family: Consolas;">;<br /></span></span></p>
<p><span style="font-family: Calibri; font-size: small;">As I tested my code, I realized I would need to set different <strong>scale</strong> values for each piece, due to the use of a 3D perspective. This was a little trickier to do in JavaScript, because animated transform values such as <strong>scale</strong>, <strong>translate</strong>, and <strong>rotate</strong> belong to the harder to access <strong>@keyframes</strong> rule. I refused to create a bunch of extra <strong>@keyframes </strong>rules in the CSS**. Instead, after some investigation, I was able to obtain the rule using the following code, which iterates through the stylesheets to get the rule I wanted.</span></p>
<p><span style="font-family: Calibri; font-size: small;">**<a title="getAnimationFrame" href="https://ie.microsoft.com/testdrive/Graphics/RequestAnimationFrame/Default.html">requestAnimationFrame</a> is another way to go. More on this in a later post.</span></p>
<p><span style="font-size: small;"><strong><span style="font-family: Calibri;">Note: &nbsp;</span></strong>If </span><span style="font-size: small;">you don't need to show these values changing within an animation, you can just </span><span style="font-size: small;">include them in CSS code, for example, like this: </span><span style="font-size: small;"><span style="color: black; font-family: Consolas;">transform: rotateX(180deg)</span>.</span><strong></strong></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp; var cssRule;</span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp; // Returns a reference to the specified CSS rule(s).</span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp; function</span><span style="font-family: Consolas;"> getRule() {</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">var</span><span style="font-family: Consolas;"> rule;</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">var</span><span style="font-family: Consolas;"> ss = document.styleSheets;</span></span></p>
<p><span style="color: #000000;"><span style="font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">for</span><span style="font-family: Consolas;"> (</span><span style="font-family: Consolas;">var</span><span style="font-family: Consolas;"> i = 0; i &lt; ss.length; </span></span><span style="font-size: small;"><span style="font-family: Consolas;">++i) {</span></span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">// loop through all the rules!</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">for</span><span style="font-family: Consolas;"> (</span><span style="font-family: Consolas;">var</span><span style="font-family: Consolas;"> x = 0; x &lt; ss[i].cssRules.length; ++x) {</span></span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rule = ss[i].cssRules[x];</span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: Consolas;">if</span><span style="font-family: Consolas;"> (rule.name == </span><span style="font-family: Consolas;">"enterPiece"</span><span style="font-family: Consolas;"> &amp;&amp; rule.type </span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; == CSSRule.KEYFRAMES_RULE) {</span></span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cssRule = rule;</span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="color: #000000; font-family: Consolas; font-size: small;">&nbsp; }</span></p>
<p><span style="font-family: Calibri; font-size: small;">To make sure I'm not getting the wrong CSS rule, I check the type, which needs to be CSSRule.KEYFRAMES_RULE, and I check the name. It's best to run this code during app initialization, and cache any rules which you need to modify in JavaScript.</span></p>
<p><span style="font-size: small;"><strong><span style="font-family: Calibri;">Note: </span></strong>For non-IE browsers, check </span><span style="font-size: small;">current recommendations for using the CSSRule.KEYFRAMES_RULE.</span></p>
<p><span style="font-family: Calibri; font-size: small;">Once I had the right rule, I had to change it. The API documentation led me to think that I should use <a href="https://msdn.microsoft.com/en-us/library/ie/hh772388(v=vs.85).aspx">insertRule</a>, but some testing indicated otherwise. Instead, I used <strong>appendRule </strong>along with <strong>deleteRule</strong>.</span></p>
<p><span style="font-family: Calibri; font-size: small;">First, I needed to clear out the current rule values. To use <strong>deleteRule</strong>, you must pass an index to indicate which part of the existing rule to delete. An index of 0 indicates the <strong>from </strong>portion (that is, the "0%" portion) of the rule. Once I deleted the rule parts, I replaced them using <strong>appendRule</strong>, and here I passed in my dynamically set scale values.</span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp; cssRule.deleteRule(</span><span style="font-family: Consolas;">"0"</span><span style="font-family: Consolas;">);</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp; cssRule.deleteRule(</span><span style="font-family: Consolas;">"1"</span><span style="font-family: Consolas;">);</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp; cssRule.appendRule(</span><span style="font-family: Consolas;">"0% { transform: translateY(-150px) "</span></span></p>
<p><span style="color: #000000; font-size: small;"><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + scale +</span><span style="font-family: Consolas;">"; opacity: 0; }"</span><span style="font-family: Consolas;">);</span></span></p>
<p><span style="font-family: Consolas;">&nbsp; cssRule.appendRule(</span><span style="font-family: Consolas;">"100% { transform: translateY(0px) "</span></p>
<p><span style="font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + scale + </span><span style="font-family: Consolas;">"; opacity: 1; }"</span>);</p>
<p>&nbsp;</p>
<p><span style="font-family: Calibri; font-size: small;">And this worked!</span></p>
<p><span style="font-family: Calibri; font-size: small;">In <a title="Part II of this series" href="https://blogs.msdn.com/b/msdn_answers/archive/2013/12/05/part-ii-running-multiple-css3-and-html5-animations-windows-store-ie.aspx">Part II of this series</a>, I talk about running multiple animations and using <strong>requestAnimationFrame</strong>. I'll share the full code when it's closer to final state.</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Creating a grid of data-bound buttons in a Windows Phone 8 app – templates and styles, oh my!</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/creating-a-grid-of-data-bound-buttons-in-a-windows-phone-8-app-templates-and-styles-oh-my</link>
      <pubDate>Fri, 01 Nov 2013 13:46:55 GMT</pubDate>
      <dc:creator><![CDATA[Cheryl Simmons]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2013/11/01/creating-a-grid-of-data-bound-buttons-in-a-windows-phone-8-app-templates-and-styles-oh-my/</guid>
      <description><![CDATA[Recently I started working on a new coding project. My long-term goal is to create a word game that...]]></description>
      <content:encoded><![CDATA[<p>Recently I started working on a new coding project. My long-term goal is to create a word game that targets Windows Phone and Windows, optimizing code reuse through Portable Class Libraries (PCL). I thought starting with the UI would be a nice break from writing about <a href="https://blogs.msdn.com/b/dotnet/archive/2013/08/07/documentation-updates-for-net-4-5-1.aspx">all things CLR/BCL</a>, which is my latest gig here at MS, and I chose the Windows Phone UI as my starting point.</p>  <p>For my game, I want to create a 5x5 grid of buttons that are bound to a list of letters that display a character value and a point value. Something like this:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/1832.image_6844E613.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/1832.image_5F00_6844E613.png"><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/2402.image_thumb_4AD29507.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/2402.image_5F00_thumb_5F00_4AD29507.png" width="190" height="154" /></a> </p>  <p>I was surprised that there wasn’t more examples of how to display a bunch of bound buttons in a grid, as this seems to be a pretty common scenario. I was also surprised at how quickly I was deep into setting styles, data templates and control templates, so I thought I would share how I created my UI.</p>  <h2>The Data</h2>  <p>Since I need to display letters, I created a simple letter object that stores a character value, a base point value (my game increments the points during play), and a count for how many of each letter are contained in my list.</p>  <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">   <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">     <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> Letter</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">public</span> Char Character { get; set; }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>     <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">int</span> BaseValue { get; set; }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>     <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">int</span> Count { get; set; }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>In my code behind, I created a property on my Page named LetterList, which is an ObservableCollection of letters. I set the list as my data context for the Page.</p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">this</span>.DataContext = LetterList;</pre>
<!--CRLF--></div>
</div>

<p>So I had my data, I just needed to figure out the UI.</p>

<h2>Changing the appearance of the default Button</h2>


<p>Out of the box, a Windows Phone button looks like this. </p>

<p>&#160;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/0358.image_2AB7884A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/0358.image_5F00_2AB7884A.png"><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/0876.image_thumb_71A0AB47.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/0876.image_5F00_thumb_5F00_71A0AB47.png" width="69" height="53" /></a></p>

<p>I wanted something like this:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/7723.image_23984BD2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/7723.image_5F00_23984BD2.png"><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/6237.image_thumb_037D3F15.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/6237.image_5F00_thumb_5F00_037D3F15.png" width="61" height="61" /></a> </p>

<p>I needed a couple of changes for the button to look how I want.</p>

<ol>
  <li>The border needs to move closer to the actual edge of the button (I am pretty sure this violates some style rule, but that’s what I wanted)</li>

  <li>The letter character should display in the center, in a large font, and the point value for the character to the lower right of the letter character.</li>
</ol>

<p>I thought Changing #2 was easy. I created a <b><a href="https://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.datatemplate(v=vs.105).aspx">DataTemplate</a></b> for <b>Button</b> that set the set the Content property to a <b>StackPanel</b> and the StackPanel contains two <b>TextBlock</b> controls, one to display the character value, and one to display the point value. </p>

<p>But there is some layering here that is a little tricky.</p>

<ul>
  <li> A <b>DataTemplate</b> is a reusable resource that sets the structure for the data it contains. That said; you can also apply a style to the data in the template, which I did, to establish the height and width for the button, and the color and thickness of the button border.</li>

  <li> I discovered that I needed to alter the <a href="https://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.controls.controltemplate(v=vs.105).aspx">ControlTemplate</a> to change the border <b>Margin, </b>and therefore display the border at the outside edge of the button. This property is a dependency property but it is not template-bound, meaning I can’t set it directly and have it override the default property like I did with the border color and thickness. </li>

  <li>The control template is a property of the Style. There is probably a good reason for this, in the sense that the original button author did not want me messing with the border margin of a button, but I want to show you how to do it regardless. <a href="https://msdn.microsoft.com/en-us/library/windowsphone/develop/cc221408(v=vs.105).aspx">This article</a> describes the basics of dependency properties and value precedence if you want some more information.</li>
</ul>

<p>In summary, this means I need to set the control template in the style, which is set in the data template. Got that?</p>

<p>I remembered how to do all the DataTemplate stuff. I create two text block controls, set their font size and text alignment how I want and bind them to the letter character and value. I also set the style to my custom style, which I’ll show a bit later. Here’s how my data template looks:</p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> &lt;DataTemplate x:Name=<span style="color: rgb(0, 96, 128);">&quot;buttonTemplate&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>     &lt;Button Style=<span style="color: rgb(0, 96, 128);">&quot;{StaticResource LetterButton}&quot;</span> Click=<span style="color: rgb(0, 96, 128);">&quot;Button_Click_1&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>         &lt;Button.Content&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>             &lt;StackPanel  Orientation=<span style="color: rgb(0, 96, 128);">&quot;Horizontal&quot;</span>&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>                 &lt;TextBlock Text=<span style="color: rgb(0, 96, 128);">&quot;{Binding Character}&quot;</span>  TextAlignment=<span style="color: rgb(0, 96, 128);">&quot;Left&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>                    VerticalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Top&quot;</span> HorizontalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Left&quot;</span> FontSize=<span style="color: rgb(0, 96, 128);">&quot;35&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>                 &lt;/TextBlock&gt; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>                 &lt;TextBlock Text=<span style="color: rgb(0, 96, 128);">&quot;{Binding BaseValue}&quot;</span> TextAlignment=<span style="color: rgb(0, 96, 128);">&quot;Right&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>                   FontSize=<span style="color: rgb(0, 96, 128);">&quot;15&quot;</span>  VerticalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Bottom&quot;</span> HorizontalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Right&quot;</span>/&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>             &lt;/StackPanel&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>         &lt;/Button.Content&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span>     &lt;/Button&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: rgb(96, 96, 96);">  13:</span> &lt;/DataTemplate&gt;</pre>
<!--CRLF--></div>
</div>

<ol>&#160; <p>&#160;</p>
  </ol>

<p>Next I needed to tackle the control template, which frankly intimidated me. The control template contains the entire visual tree for a control, and usually trying to create one that contains all of the behavior the original control author included is difficult. Imagine my happy surprise when I discovered how easy it is to change a control template in Visual Studio these days. I selected my button, right clicked and saw the following menu choices. </p>

<p>&#160;</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/7484.image_38AF067A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/7484.image_5F00_38AF067A.png"><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/0121.image_thumb_4A8B9A47.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/0121.image_5F00_thumb_5F00_4A8B9A47.png" width="313" height="214" /></a> </p>

<p>I chose to edit a copy of the template and simply adjusted the property that I cared about, the Margin for the border.</p>

<p>Following is my control template, style and data template. I’ve omitted most of the control template, just showing the portion I modified. You’ll see that most of the properties of the ButtonBackground border are specified as TemplateBinding, which exposes them to be set locally.</p>

<p>You will also see that the Style contains and sets the ControlTemplate, and the DataTemplate sets the Style. </p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> &lt;ControlTemplate x:Key=<span style="color: rgb(0, 96, 128);">&quot;ButtonBaseControlTemplate1&quot;</span> TargetType=<span style="color: rgb(0, 96, 128);">&quot;ButtonBase&quot;</span>&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>     &lt;Grid&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>   </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>        &lt;!--Unchanged portions omitted <span style="color: rgb(0, 0, 255);">for</span> brevity--&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>         &lt;Border x:Name=<span style="color: rgb(0, 96, 128);">&quot;ButtonBackground&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>             BorderBrush=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding BorderBrush}&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>             BorderThickness=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding BorderThickness}&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>             CornerRadius=<span style="color: rgb(0, 96, 128);">&quot;4&quot;</span> Background=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding Background}&quot;</span> Margin=<span style="color: rgb(0, 96, 128);">&quot;0&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>             &lt;ContentControl x:Name=<span style="color: rgb(0, 96, 128);">&quot;ContentContainer&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>             Foreground=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding Foreground}&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>             HorizontalContentAlignment=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding HorizontalContentAlignment}&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span>             VerticalContentAlignment=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding VerticalContentAlignment}&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: rgb(96, 96, 96);">  13:</span>             Padding=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding Padding}&quot;</span> Content=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding Content}&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum14" style="color: rgb(96, 96, 96);">  14:</span>             ContentTemplate=<span style="color: rgb(0, 96, 128);">&quot;{TemplateBinding ContentTemplate}&quot;</span>/&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: rgb(96, 96, 96);">  15:</span>         &lt;/Border&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum16" style="color: rgb(96, 96, 96);">  16:</span>     &lt;/Grid&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: rgb(96, 96, 96);">  17:</span> &lt;/ControlTemplate&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum18" style="color: rgb(96, 96, 96);">  18:</span> &lt;Style TargetType=<span style="color: rgb(0, 96, 128);">&quot;Button&quot;</span> x:Name=<span style="color: rgb(0, 96, 128);">&quot;LetterButton&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: rgb(96, 96, 96);">  19:</span>     &lt;Setter Property=<span style="color: rgb(0, 96, 128);">&quot;Template&quot;</span> Value=<span style="color: rgb(0, 96, 128);">&quot;{StaticResource ButtonBaseControlTemplate1}&quot;</span> /&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum20" style="color: rgb(96, 96, 96);">  20:</span>     &lt;Setter Property=<span style="color: rgb(0, 96, 128);">&quot;Height&quot;</span> Value=<span style="color: rgb(0, 96, 128);">&quot;88&quot;</span> /&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: rgb(96, 96, 96);">  21:</span>     &lt;Setter Property=<span style="color: rgb(0, 96, 128);">&quot;Width&quot;</span> Value=<span style="color: rgb(0, 96, 128);">&quot;88&quot;</span> /&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum22" style="color: rgb(96, 96, 96);">  22:</span>     &lt;Setter Property=<span style="color: rgb(0, 96, 128);">&quot;BorderBrush&quot;</span> Value=<span style="color: rgb(0, 96, 128);">&quot;White&quot;</span> /&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: rgb(96, 96, 96);">  23:</span>     &lt;Setter Property=<span style="color: rgb(0, 96, 128);">&quot;BorderThickness&quot;</span> Value=<span style="color: rgb(0, 96, 128);">&quot;3&quot;</span> /&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum24" style="color: rgb(96, 96, 96);">  24:</span> &lt;/Style&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: rgb(96, 96, 96);">  25:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum26" style="color: rgb(96, 96, 96);">  26:</span> &lt;DataTemplate x:Name=<span style="color: rgb(0, 96, 128);">&quot;buttonTemplate&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: rgb(96, 96, 96);">  27:</span>     &lt;Button Style=<span style="color: rgb(0, 96, 128);">&quot;{StaticResource LetterButton}&quot;</span> Click=<span style="color: rgb(0, 96, 128);">&quot;Button_Click_1&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum28" style="color: rgb(96, 96, 96);">  28:</span>         &lt;Button.Content&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: rgb(96, 96, 96);">  29:</span>             &lt;StackPanel  Orientation=<span style="color: rgb(0, 96, 128);">&quot;Horizontal&quot;</span>&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum30" style="color: rgb(96, 96, 96);">  30:</span>                 &lt;TextBlock Text=<span style="color: rgb(0, 96, 128);">&quot;{Binding Character}&quot;</span>  TextAlignment=<span style="color: rgb(0, 96, 128);">&quot;Left&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: rgb(96, 96, 96);">  31:</span>                    VerticalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Top&quot;</span> HorizontalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Left&quot;</span> FontSize=<span style="color: rgb(0, 96, 128);">&quot;35&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum32" style="color: rgb(96, 96, 96);">  32:</span>                 &lt;/TextBlock&gt; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: rgb(96, 96, 96);">  33:</span>                 &lt;TextBlock Text=<span style="color: rgb(0, 96, 128);">&quot;{Binding BaseValue}&quot;</span> TextAlignment=<span style="color: rgb(0, 96, 128);">&quot;Right&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum34" style="color: rgb(96, 96, 96);">  34:</span>                   FontSize=<span style="color: rgb(0, 96, 128);">&quot;15&quot;</span>  VerticalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Bottom&quot;</span> HorizontalAlignment=<span style="color: rgb(0, 96, 128);">&quot;Right&quot;</span>/&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: rgb(96, 96, 96);">  35:</span>             &lt;/StackPanel&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum36" style="color: rgb(96, 96, 96);">  36:</span>         &lt;/Button.Content&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: rgb(96, 96, 96);">  37:</span>     &lt;/Button&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum38" style="color: rgb(96, 96, 96);">  38:</span> &lt;/DataTemplate&gt;</pre>
<!--CRLF--></div>
</div>

<h2>Using WrapPanel to get the look of a Grid</h2>

<p>My button looks good, so the next step is to lay it out in a grid, and bind it to my list of letters. I first tried a Grid layout, but I couldn’t get my data binding to work properly. I was pretty sure the buttons needed to be displayed in some type of list control to get the data binding right. <a href="https://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.controls.listbox(v=vs.105).aspx">ListBox</a> appeared to be the control I needed, but I didn’t know how to display a ListBox so it looked like a grid.</p>

<p>I poked around and discovered the WrapPanel control in the <a href="https://www.nuget.org/packages/WPtoolkit">Windows phone toolkit</a>, which is available through NuGet.</p>

<p>The layout for the ListBox is also a little tricky. In order for my ListBoxItems to display correctly, I needed to set the ItemTemplate, which determines the visual structure of each ListBoxItem contained in the ListBox, to the data template I showed previously. This mean each list box item will have contain a button, which in turn contains two text blocks with my letter character and point value.</p>

<p>Finally, to layout my items in a grid-like way, I set the ListBox.ItemsPanelTemplate to a WrapPanel. The ItemsPanelTemplate property determines the layout of each item in the ListBox control. </p>

<p>I turned off scrolling on my <b>ListBox</b>, by setting the <b>ScrollViewer.VerticalScrollBarVisibility</b> property to disabled so just my 5x5 grid displays on the screen.</p>

<p>My XAML for the ContentPanel of my phone page looks like this:</p>

<pre class="csharpcode">       </pre>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> &lt;Grid x:Name=<span style="color: rgb(0, 96, 128);">&quot;ContentPanel&quot;</span> Grid.Row=<span style="color: rgb(0, 96, 128);">&quot;1&quot;</span> Margin=<span style="color: rgb(0, 96, 128);">&quot;12,0,12,0&quot;</span> ShowGridLines=<span style="color: rgb(0, 96, 128);">&quot;True&quot;</span> &gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>         &lt;ListBox Height=<span style="color: rgb(0, 96, 128);">&quot;440&quot;</span>  Name=<span style="color: rgb(0, 96, 128);">&quot;ButtonList&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>            ItemsSource=<span style="color: rgb(0, 96, 128);">&quot;{Binding}&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>            ItemTemplate=<span style="color: rgb(0, 96, 128);">&quot;{StaticResource buttonTemplate}&quot;</span> </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>            ScrollViewer.VerticalScrollBarVisibility=<span style="color: rgb(0, 96, 128);">&quot;Disabled&quot;</span>&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>             &lt;ListBox.ItemsPanel&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>                 &lt;ItemsPanelTemplate&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>                     &lt;toolkit:WrapPanel Width=<span style="color: rgb(0, 96, 128);">&quot;440&quot;</span>  /&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>                 &lt;/ItemsPanelTemplate&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>             &lt;/ListBox.ItemsPanel&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>         &lt;/ListBox&gt;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span> &lt;/Grid&gt;</pre>
<!--CRLF--></div>
</div>


<p>And finally, when I ran my app, I saw success:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/5483.image_381D9B50.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/5483.image_5F00_381D9B50.png"><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/86/metablogapi/8625.image_thumb_2CF41106.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-86-metablogapi/8625.image_5F00_thumb_5F00_2CF41106.png" width="156" height="234" /></a> </p>


<p>I am sure this code will continue to evolve as I create my app, but for now, I am happy with the progress I’ve made.</p>]]></content:encoded>
    </item>
    <item>
      <title>Access a Web service using the Hub template (Windows 8.1)</title>
      <link>https://docs.microsoft.com/archive/blogs/msdn_answers/access-a-web-service-using-the-hub-template-windows-8-1</link>
      <pubDate>Mon, 05 Aug 2013 10:34:00 GMT</pubDate>
      <dc:creator><![CDATA[Mike Jones (CSI)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/msdn_answers/2013/08/05/access-a-web-service-using-the-hub-template-windows-8-1/</guid>
      <description><![CDATA[Visual Studio 2013 Preview includes a new project template for Windows 8.1 apps, the Hub App project...]]></description>
      <content:encoded><![CDATA[<p><span style="color: black; font-family: Segoe UI; font-size: small;">Visual Studio 2013 Preview includes a new project template for Windows 8.1 apps, the Hub App project template. Out of the box, the Hub template demonstrates an implementation of a <a href="https://msdn.microsoft.com/en-us/library/windows/apps/hh761500.aspx">hierarchical navigation pattern</a> for Windows Store apps. To populate &lt;img&gt; elements, ListView controls, and text elements&nbsp;in the UI, the template uses two data models: (1) static sample data used to populate ListView controls (in data.js), and (2) static string resources to support globalization, which are stored in .resjson files. Declarative functions in the HTML obtain the sample data from data.js. To make the declarative functions work with asynchronous data requires some code modifications.</span></p>
<p><span style="color: black; font-family: Segoe UI; font-size: small;">The <a href="https://code.msdn.microsoft.com/windowsapps/Hub-template-sample-with-4b70002d">Hub template sample app</a> (JavaScript only, at present) demonstrates how to customize the data model in the Hub template to support asynchronous data (the app grabs images and text from a public Web service).</span></p>
<p><span style="color: black; font-family: Segoe UI; font-size: small;">Here's a few other things that the sample app shows:</span></p>
<ul>
<li>
<p><span style="font-size: small;"><span style="color: black; font-family: Segoe UI;">How to implement data binding for the template's &lt;img&gt; elements and ListView controls. </span></span></p>
</li>
<li>
<p><span style="font-size: small;"><span style="color: black; font-family: Segoe UI;">How to handle user-initiated requests for new data. </span></span></p>
</li>
<li>
<p><span style="font-size: small;"><span style="color: black; font-family: Segoe UI;">How to process JSON data obtained from a Web service. </span></span></p>
</li>
<li>
<p><span style="font-size: small;"><span style="color: black; font-family: Segoe UI;">How to add a progress indicator. </span></span></p>
</li>
</ul>
<p><span style="color: black; font-family: Segoe UI; font-size: small;">The app retrieves public photos and data available on Flickr using the Flickr public Web feed. You can replace this easily with another JSON, RSS, or Atom feed. The grouping of data is for demonstration purposes, and is somewhat arbitrary (the first five images are used for Hub template &lt;img&gt; elements, the rest are used ListView controls), but this can be easily modified to support data that is inherently group-based.</span></p>
<p><span style="font-size: small;"><strong><span style="color: black; font-family: Segoe UI;">Note:</span></strong><span style="color: black; font-family: Segoe UI;"> Because the globalized string resources can be easily replaced, the sample app leaves these strings unmodified.</span></span></p>
<p><span style="color: black; font-family: Segoe UI; font-size: small;">Link:</span></p>
<p><span style="color: black; font-family: Segoe UI; font-size: small;"><a href="https://code.msdn.microsoft.com/windowsapps/Hub-template-sample-with-4b70002d">Hub template sample with asynchronous data</a></span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>