SilverlightShow: Silverlight Community http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) Windows 8.1: Easily send your notifications to tiles, toasts and badges <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-8.1-Easily-send-your-notifications-to-tiles-toasts-and-badges.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/1bpVBwW" data-text="Read @aboschin's article '#Win8.1: Easily send notifications to tiles, toasts & badges' #win8dev" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Easily-send-your-notifications-to-tiles-toasts-and-badges.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-8.1-Easily-send-your-notifications-to-tiles-toasts-and-badges.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p style="text-align: justify;">Sending notifications from inside your application, both from code of from a push notification channel, is being a must when developing with Windows 8.1.  Sending a notification is at all a simple task, but it involves boring and repetitive things that always need to be done. Recently I’ve published a new library made to oversimplify this task and made it straightforward in both the scenarios, from the server side with a push notification or from the running app both in foreground and in background.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Webinar recording: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-8.1-The-Windows-Search-API.aspx">Andrea's article series on Windows 8.1</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <h3 style="text-align: justify;">Notifications: the usual way</h3> <p style="text-align: justify;">All in all, sending a notification to a tile, a toast or a badge is a simple task. At the very end you have only to build a fragment of xml and then send it to the runtime using the right manager. The very hard task to me, is that you need to create the xml, from scratch or using a template, and this implies you always remember the structure and the fields you have to fill to make this notification valid. </p> <p style="text-align: justify;">This means you always have to browse documentation (here is the tile template catalog <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx)">http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx)</a> to detect the right format of the output xml on the basis of the combination of images, title and content you need and then use the XmlDocument to fill out the template. </p> <p style="text-align: justify;">As an example if you would like to get a tile notification for a tile, you need to write something like the code below. First of all, after going in the template catalog you have to get the template using the GetTemplateContent method:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> XmlDocument tileXml = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageAndText01);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Then, with the structure of the xml in mind you have to fill the fields. This template has two fields, an image and a text line. So you scan the template for the text node and fill it this way:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> XmlNodeList tileTextNode = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> tileXml.GetElementsByTagName(<span style="color: #006080;">"text"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">if</span> (tileTextNode != <span style="color: #0000ff;">null</span> && tileTextNode.Length > 0)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> tileTextAttributes[0].InnerText = <span style="color: #006080;">"This is a notification build by hand!"</span>;</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Then the same thing is done with the image that has instead two attributes to fill. So again find the node and set the attributes:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> XmlNodeList tileImageNode = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> tileXml.GetElementsByTagName(<span style="color: #006080;">"image"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">if</span> (tileImageNode != <span style="color: #0000ff;">null</span> && tileImageNode.Length > 0)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> ((XmlElement)tileImageNode[0]).SetAttribute(<span style="color: #006080;">"src"</span>, <span style="color: #006080;">"ms-appx:///images/mytileimage.png"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> ((XmlElement)tileImageNode[0]).SetAttribute(<span style="color: #006080;">"alt"</span>, <span style="color: #006080;">"The tile image text"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">With tile notifications usually you need to send an update for each size your app implements. Usually, when you choose to use a tile notification you provide at least two sizes so the code above needs to be duplicated and merged to create a single notification that contains both the sizes. With the XmlDocument this task imply you have to extract part of the notification and import it into the other one. The resulting XML should be like this:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <tile></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <visual version=<span style="color: #006080;">"2"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <binding template=<span style="color: #006080;">"TileWide310x150ImageAndText01"</span> fallback=<span style="color: #006080;">"TileWideImageandText01"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <image id=<span style="color: #006080;">"1"</span> src=<span style="color: #006080;">"ms-appx:///images/mytileimage.png"</span> alt=<span style="color: #006080;">"The tile image text"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <text id=<span style="color: #006080;">"1"</span>>This <span style="color: #0000ff;">is</span> a notification build by hand!</text></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> </binding></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <binding template=<span style="color: #006080;">"TileSquare150x150Text04"</span> fallback=<span style="color: #006080;">"TileSquareText04"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <text id=<span style="color: #006080;">"1"</span>>This <span style="color: #0000ff;">is</span> a notification build by hand!</text></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> </binding></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> </visual></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> </tile></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Each <binding> node represents a single tile size. To build this you do something like this:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> XmlDocument squareTileXml = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text04);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> XmlNodeList squareTileTextNode = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> squareTileXml.GetElementsByTagName(<span style="color: #006080;">"text"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">if</span> (squareTileTextNode != <span style="color: #0000ff;">null</span> && squareTileTextNode.Length > 0)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> squareTileTextNode[0].AppendChild(squareTileXml.CreateTextNode(<span style="color: #006080;">"This is a notification build by hand!"</span>));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Finally the templates should be merged together:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> IXmlNode node = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> tileXml.ImportNode(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> squareTileXml.GetElementsByTagName(<span style="color: #006080;">"binding"</span>).Item(0), <span style="color: #0000ff;">true</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> tileXml.GetElementsByTagName(<span style="color: #006080;">"visual"</span>).Item(0).AppendChild(node);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This code, taken from the MSDN documentation is probably nothing of too hard, but it requires time and the deep knowledge of the xml manipulation tecniques. After having build a number of these I’ve finally decided to create a simple library to make this work easy as opening a simple messagebox.</p> <h3 style="text-align: justify;">Introducing the XPG.Toolkit.Notifications library</h3> <p style="text-align: justify;">Saying “simple library” may sounds that it have been build in a few hours. Unfortunately, since there are almost 75 templates only for tiles and the great part of them have two version of the xml (one for version 1 and the other for version 2), building a compehensive library that also includes toasts and badged took me a number of days of work. But now, with the <a target="_blank" href="http://www.xamlplayground.org/page/XPG-Toolkit-Notification-library.aspx">XPG Notification Library</a>, sending an update like the one I’ve shown in the previous section is easy like drinking a glass of water:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> INotificationManager manager = <span style="color: #0000ff;">new</span> NotificationManager();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> manager.PublishTile(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">new</span> Tile</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> Visual = <span style="color: #0000ff;">new</span> TileVisual</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Bindings = <span style="color: #0000ff;">new</span> TileBinding[] {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">new</span> TileWide310x150ImageAndText01</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> Text1 = <span style="color: #006080;">"This is a notification build easy"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> ImageSource1 = <span style="color: #0000ff;">new</span> Uri(<span style="color: #006080;">"ms-appx:///images/mytileimage.png"</span>),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> ImageText1 = <span style="color: #006080;">"The tile image text"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">new</span> TileSquare150x150Text04{</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> Text1 = <span style="color: #006080;">"This is a notification build easy"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> });</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">As you can see you have only to build a couple of object instances, corresponding to the tile sizes you have to update and then add both to the notification structure. At the end, using a NotificationManager you post the notification to the right update manager. This is for sure way too better because Visual Studio helps you with intellisense in discovering the properties you have to fill and you also use strictly typed properties (in this case the image Uri) to avoid unwanted errors that make the notification fail silently with XML. </p> <p style="text-align: justify;">The concept behind the library is definitely simple. It is a big collection of xml serializable classes that matches all the available templates. All the templates actually supports both the old version 1 and the new version 2 shapes. You can forget the difference between the two versions and directly use the old or new version using its original name:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">// initialize and old (version 1) tile template</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> TileSquareText01 oldTile = <span style="color: #0000ff;">new</span> TileSquareText01();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #008000;">// initialize the new (version 2) tile template</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> TileSquare150x150Text01 newTile = <span style="color: #0000ff;">new</span> TileSquare150x150Text01();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #008000;">// everywhere possible the old template is base class for the new one</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #008000;">// so it is possible the following assignment</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> oldTile = newTile;</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">All the templates are able to directly serialize to a string using a simple assignment. This is because the base class implements an operator overloading for the assignment to a string variable. Here is and example:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var tile = <span style="color: #0000ff;">new</span> TileWide310x150ImageAndText01</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Text1 = <span style="color: #006080;">"This is a notification build easy"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> ImageSource1 = <span style="color: #0000ff;">new</span> Uri(<span style="color: #006080;">"ms-appx:///images/mytileimage.png"</span>),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> ImageText1 = <span style="color: #006080;">"The tile image text"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Debug.WriteLine(tile);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The code above outputs the following XML to the debug console:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">binding</span> <span style="color: #ff0000;">fallback</span><span style="color: #0000ff;">="TileWideImageAndText01"</span> <span style="color: #ff0000;">template</span><span style="color: #0000ff;">="TileWide310x150ImageAndText01"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">image</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">="ms-appx:///images/mytileimage.png"</span> <span style="color: #ff0000;">alt</span><span style="color: #0000ff;">="The tile image text"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">text</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span>This is a notification build easy<span style="color: #0000ff;"></</span><span style="color: #800000;">text</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">binding</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Obviously you can also assign the output to a string variable or to a XDocument instance</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var tile = <span style="color: #0000ff;">new</span> TileWide310x150ImageAndText01</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Text1 = <span style="color: #006080;">"This is a notification build easy"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> ImageSource1 = <span style="color: #0000ff;">new</span> Uri(<span style="color: #006080;">"ms-appx:///images/mytileimage.png"</span>),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> ImageText1 = <span style="color: #006080;">"The tile image text"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> XDocument xDocument = tile;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">string</span> xmlString = tile;</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Getting the xml from a notification may be useful if you need to send a push notification. This is possible because the library is built as a PCL (portable class library) so you can generate notifications also in a server code that pushed it to the Windows Notification Service (WNS). The serializations actually works at every level of the hierarchy, allowing to serialize the whole structure with a number of notifications into it.</p> <h3 style="text-align: justify;">Not only for tiles. Toasts, badges and…</h3> <p style="text-align: justify;">As I said initially you can send also other types of notifications. The library includes all the templates for toast and badge notification. Using the same notification manager you will find the PublishToast and PublishBadge methods:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> manager.PublishToast(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">new</span> Toast</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> Visual = <span style="color: #0000ff;">new</span> ToastVisual</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> Binding = <span style="color: #0000ff;">new</span> ToastText04</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Text1 = <span style="color: #006080;">"This is a toast notification"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> Text2 = <span style="color: #006080;">"Created with XPG Toolkit"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> Text3 = <span style="color: #006080;">"by A. Boschin"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> });</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This code sends a tile notification using the ToastText04 template. As for tiles it exposes properties with the same name of the online catalog so it is easy to understand the content to provide. Equally you can send an badge notification this way:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> manager.PublishBadge(<span style="color: #0000ff;">new</span> Badge</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Value = BadgeValue.Attention,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> Version = 1</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> });</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The BadgeValue property is an enumerator but you can also supply and integer to show a number on the badge, using a value from 0 to 99. Here is the sample:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> manager.PublishBadge(<span style="color: #0000ff;">new</span> Badge</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Value = (BadgeValue)42,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> Version = 1</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> });</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Windows 8.1 also support scheduled alarm notifications that have a given delivery time and a snooze interval. The methods in the NotificationManager allow to specify these values for every Toast and Tile notifications:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> manager.PublishToast(<span style="color: #0000ff;">new</span> Toast</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Duration = <span style="color: #006080;">"long"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> Launch = <span style="color: #006080;">"12345"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> Audio = <span style="color: #0000ff;">new</span> ToastAudio</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> Loop = <span style="color: #0000ff;">true</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Source = <span style="color: #006080;">"ms-winsoundevent:Notification.Looping.Alarm2"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> Visual = <span style="color: #0000ff;">new</span> ToastVisual</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> Binding = <span style="color: #0000ff;">new</span> ToastText01</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> Text1 = <span style="color: #006080;">"Alarm!"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> Scenario = <span style="color: #0000ff;">new</span> AlarmScenario</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> CanDismiss = <span style="color: #0000ff;">true</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> CanSnooze = <span style="color: #0000ff;">true</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }, DateTimeOffset.Now.AddMinutes(1), TimeSpan.FromSeconds(60), 3);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The previous code sends a scheduled toast notification that is raised one minute after, and it snooze three times every 60 seconds.</p> <h3 style="text-align: justify;">Supporting Mocking</h3> <p style="text-align: justify;">As a final note, you have to notice that the library has been build with mocking in mind. The NotificationManager is based on a INotificationManager interface and it may support a dependency injection container. This lets you to add at runtime the NotificationManager instance and change it during tests with a mock that track the calls to the manager’s methods. </p> <p style="text-align: justify;">The library is enforced by 136 unit tests that ensures the correct output to the notification system. So you can rely for sure on it. In the future I’m planning to add some other methods to the NotificationManager the sends easily standard notifications with very few lines of code, removing the needs of creating the wrapping package of the notification. </p> <p style="text-align: justify;">If you are interested, the library is <a href="https://www.nuget.org/packages/XPG.Toolkit.Notifications/1.0.5114">available on Nuget</a> with the <a target="_blank" href="http://opensource.org/licenses/MS-PL">MS-PL</a> license, and it can be downloaded easily directly from Visual Studio using the Nuget package manager. Feel free to use the library in your commercial products, free of charge. Other details here: <a href="http://www.xamlplayground.org/page/XPG-Toolkit-Notification-library.aspx" title="http://www.xamlplayground.org/page/XPG-Toolkit-Notification-library.aspx">http://www.xamlplayground.org/page/XPG-Toolkit-Notification-library.aspx</a></p> http://www.silverlightshow.net/items/Windows-8.1-Easily-send-your-notifications-to-tiles-toasts-and-badges.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Easily-send-your-notifications-to-tiles-toasts-and-badges.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Easily-send-your-notifications-to-tiles-toasts-and-badges.aspx Tue, 04 Feb 2014 12:02:00 GMT Windows 8.1: The Windows Search API <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-8.1-The-Windows-Search-API.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/K1nyAO" data-text="Read @aboschin's article 'Windows 8.1: The Windows Search API' #win8dev #win81" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-The-Windows-Search-API.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-8.1-The-Windows-Search-API.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p style="text-align: justify;">Starting from Windows 8.1, the search has slightly changed in the Windows Store apps. The old Search contract is not anymore the sole way to go, but now the app is enabled to provide its own search box. To give a better search experience, it has now the ability of integrating with the Windows Search engine with some new APIs. This imply some more work for the developer that has to load in the search engine the items he wants to make searchable, but the results is much more interesting and effective.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Webinar recording: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <h4 style="text-align: justify;">The Windows.Storage.Search namespace</h4> <p style="text-align: justify;">Inside this new namespace, it is now included the whole toolset you can use to provide an effective search. These APIs let you to add and remove items from the indexing engine attaching some properties to each item and then use some queries to retrieve this content from the engine itself. </p> <p style="text-align: justify;">There are two classes that collaborates in this work:  </p> <p style="text-align: justify;"><strong>ContentIndexer</strong>: it is the class that represents the engine where you will load the indexed items. It is a sealed class and you cannot create instances of it. You can only retrieve an instance using the GetIndexer method.</p> <p style="text-align: justify;"><strong>IndexableContent</strong>: it represents an item you can add, update and finally remove from the indexing engine. Each items has an unique Id you can use to retrieve the items after having added them.</p> <p style="text-align: justify;">So, the first thing to do to interact with the engine is to get the indexer's instance. This is done using the GetIndexer method, without parameters in the simplest case. You can also provide a name and this enables you to have more than an indexer, each one with its separated items. Always remember that the indexer, with or without a name, has a scope related to the local application and cannot be accessed by other apps.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">// retrieve the default indexer of the app</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> ContentIndexer defaultIndexer = ContentIndexer.GetIndexer();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #008000;">// retrieve a secondary indexer of the app</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> ContentIndexer otherIndexer = ContentIndexer.GetIndexer(<span style="color: #006080;">"otherIndexer"</span>);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Be aware that your store will survive when the app is closed. You can see the current revision of its content using the progressive incremental value of the Revision property. Once you get your indexer you have a couple of methods to manipulate the items in the store.</p> <p style="text-align: justify;"><strong>AddAsync</strong> : adds an item to the store <br /> <strong>UpdateAsync</strong>: retrieve an item and update its properties using the Id property <br /> <strong>DeleteAsync</strong>, <strong>DeleteMultipleAsync</strong> and <strong>DeleteAllAsync</strong>: provide some ways to remove content from the store</p> <p style="text-align: justify;">To add an item, as an example, you have first to create the IndexableContent's instance. This means you have to create an instance of the class, provide an unique Id, populate its properties you want to make available and finally add a stream of the item content. The following code shows the creation of an element and its addition to the store:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">using</span> (var stream = <span style="color: #0000ff;">new</span> InMemoryRandomAccessStream())</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #008000;">// write the content to the stream</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> var writer = <span style="color: #0000ff;">new</span> DataWriter(stream);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> writer.WriteString(content);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> await writer.StoreAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #008000;">// reset the stream to its beginning</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> stream.Seek(0);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #008000;">// create the item to add</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> IndexableContent item = <span style="color: #0000ff;">new</span> IndexableContent</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> Id = Guid.NewGuid().ToString(),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> Stream = stream,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> StreamContentType = <span style="color: #006080;">"text/plain"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #008000;">// and finally add it</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> await otherIndexer.AddAsync(item);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The item content is represented by a stream and you can use a DataWriter to generate it from the original string. At the end the stream is rewinded to the beginning so the indexable content can read from it.</p> <p style="text-align: justify;">Each item you can add can be decorated with a number of additional properties. These properties are used to search the items. A property is a name-value pair and you can use the SystemProperties class to find the correct names. The class contains a number of basic properties and some other that are specific for multimedia scenario. As an example you can provide the Encoding bitrate of an audio stream using the SystemProperties.Audio.EncodingBitrate. Here are how to add properties to the previous indexed content.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> item.Properties.Add(SystemProperties.ItemNameDisplay, <span style="color: #006080;">"LoremIpsum"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> item.Properties.Add(SystemProperties.Keywords, <span style="color: #006080;">"Lorem, ipsum, dolor, sit, amet"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> item.Properties.Add(SystemProperties.Comment, <span style="color: #006080;">"The same old lorem ipsum"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> item.Properties.Add(SystemProperties.Title, <span style="color: #006080;">"Lorem ipsum dolor sit amet"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> item.Properties.Add(SystemProperties.Media.Year, DateTime.Now.Year);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Another important property you have to handle is the language. Providing the correct language is important because the indexing engine can use it to correctly spell the properties and give a better result. It is also important to not provide a language is you do not really know the correct language of your resource. This because the engine will try to guess it analyzing the value.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var comment = <span style="color: #0000ff;">new</span> ValueAndLanguage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> comment.Language = <span style="color: #006080;">"en-US"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> comment.Value = <span style="color: #006080;">"The same old lorem ipsum"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> item.Properties.Add(SystemProperties.Comment, comment);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> await otherIndexer.AddAsync(item);</pre> <!--CRLF--></div> </div> </div> <h4 style="text-align: justify;">Performing a search</h4> <p style="text-align: justify;">Searching content is definitely easy, but you have a number of options to work with. A search is identified by a query that you create providing the search terms. Once the query has been created using the CreateQuery method, you execute it by calling the GetAsync method.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var query = otherIndexer.CreateQuery(<span style="color: #006080;">"lorem"</span>, <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">string</span>[] { SystemProperties.ItemNameDisplay });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> IEnumerable<IIndexableContent> result = await query.GetAsync();</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">As you can see the creation of the query requires the filter (in this case a simple word) and a list of properties you need to retrieve. It is important not to ask for more properties that the ones you really need to avoid unuseful works for the engine.</p> <p style="text-align: justify;">The query provides also the ability to order the returned item by some properties. This may be achieved using an additional overload of the CreateQuery method:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var query = otherIndexer.CreateQuery(<span style="color: #006080;">"lorem"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">string</span>[] { SystemProperties.ItemNameDisplay },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">new</span> SortEntry[] </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> { </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">new</span> SortEntry{ AscendingOrder = <span style="color: #0000ff;">true</span>, PropertyName = SystemProperties.Media.Year }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> IEnumerable<IIndexableContent> result = await query.GetAsync();</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The query has additional methods you can use to improve your searches. You can retrieve the count of items without retrieving the items using the GetCountAsync ad finally retrieve only the properties with the GetPropertiesAsync. </p> <p style="text-align: justify;">Until now we have passed a query made of a single word and the engines searches it into all the properties. You can also create a query using a special language called AQS (<a href="http://msdn.microsoft.com/en-us/library/bb266512" title="http://msdn.microsoft.com/en-us/library/bb266512">http://msdn.microsoft.com/en-us/library/bb266512</a><a href="http://msdn.microsoft.com/en-us/library/windows/apps/bb266512%28v=VS.85%29.aspx)">)</a>. This language allow to specify a more complex grammar that enable searches on specific properties and the use of operators. </p> <p style="text-align: justify;">The following example searches using an AQS query:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var query = otherIndexer.CreateQuery(<span style="color: #006080;">"keyword:(lorem OR ipsum)"</span>, <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">string</span>[] { SystemProperties.ItemNameDisplay });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> IEnumerable<IIndexableContent> result = await query.GetAsync();</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The query specified searches the SystemProperties.Keywords values for items that contains the words “lorem” or “ipsum”. The query language has lot of Values you can search for. </p> <p style="text-align: justify;"><strong>System.Size </strong>: evaluate the size of the item <br /> <strong>System.DateModified</strong>: enable search of items on the basis of the modification date and time</p> <h4 style="text-align: justify;">Using appcontent-ms files</h4> <p style="text-align: justify;">If the toolset I’ve explained until now does not suffices, be aware that you have also another option for feeding the indexing engine. This uses a set of files, stored into a folder in the file system. You have to create the folder and add to it the files you want to be indexed by the engine. Each file represents an item in the index and it contains all the properties you can use in the previous samples beside with the content itself. Here is a sample file:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><?</span><span style="color: #800000;">xml</span> <span style="color: #ff0000;">version</span><span style="color: #0000ff;">="1.0"</span> <span style="color: #ff0000;">encoding</span><span style="color: #0000ff;">="utf-8"</span>?<span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">IndexerSampleInformation</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Properties</span> <span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">="http://schemas.microsoft.com/Search/2013/ApplicationContent"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Name</span><span style="color: #0000ff;">></span>LoremIpsum<span style="color: #0000ff;"></</span><span style="color: #800000;">Name</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Keywords</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Keyword</span> <span style="color: #ff0000;">xml:lang</span><span style="color: #0000ff;">="en-US"</span><span style="color: #0000ff;">></span>Lorem<span style="color: #0000ff;"></</span><span style="color: #800000;">Keyword</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Keyword</span> <span style="color: #ff0000;">xml:lang</span><span style="color: #0000ff;">="en-US"</span><span style="color: #0000ff;">></span>ipsum<span style="color: #0000ff;"></</span><span style="color: #800000;">Keyword</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Keyword</span> <span style="color: #ff0000;">xml:lang</span><span style="color: #0000ff;">="en-US"</span><span style="color: #0000ff;">></span>dolor<span style="color: #0000ff;"></</span><span style="color: #800000;">Keyword</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Keyword</span> <span style="color: #ff0000;">xml:lang</span><span style="color: #0000ff;">="en-US"</span><span style="color: #0000ff;">></span>sit<span style="color: #0000ff;"></</span><span style="color: #800000;">Keyword</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Keyword</span> <span style="color: #ff0000;">xml:lang</span><span style="color: #0000ff;">="en-US"</span><span style="color: #0000ff;">></span>amet<span style="color: #0000ff;"></</span><span style="color: #800000;">Keyword</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Keywords</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Comment</span><span style="color: #0000ff;">></span>The same old lorem ipsum<span style="color: #0000ff;"></</span><span style="color: #800000;">Comment</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AdditionalProperties</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Property</span> <span style="color: #ff0000;">Key</span><span style="color: #0000ff;">="System.Title"</span><span style="color: #0000ff;">></span>Lorem ipsum dolor sit amet<span style="color: #0000ff;"></</span><span style="color: #800000;">Property</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">AdditionalProperties</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Properties</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">IndexerSampleSpecificElement</span> <span style="color: #ff0000;">sc:IndexableContent</span><span style="color: #0000ff;">="true"</span> <span style="color: #ff0000;">xmlns:sc</span><span style="color: #0000ff;">="http://schemas.microsoft.com/Search/2013/ApplicationContent"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> Lorem ipsum dolor sit amet, consectetur adipiscing elit.</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> Morbi et orci fringilla libero vestibulum luctus.</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> Aliquam lacus neque, vehicula eget scelerisque sed, tristique rhoncus felis.</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">IndexerSampleSpecificElement</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">IndexerSampleInformation</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">You can embed this files in your solution and copy it to the folder using the common file IO API but you can also create them at runtime. Once the files has been added you are able to create a query using a set of specific APIs:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(<span style="color: #006080;">"Indexed"</span>, CreationCollisionOption.OpenIfExists);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> QueryOptions options = <span style="color: #0000ff;">new</span> QueryOptions();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> options.IndexerOption = IndexerOption.OnlyUseIndexer;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> options.ApplicationSearchFilter = Windows.Storage.SystemProperties.ItemNameDisplay + <span style="color: #006080;">":\"LoremIpsum\""</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> StorageFileQueryResult query = folder.CreateFileQueryWithOptions(options);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> IEnumerable<StorageFile> foundFiles = await query.GetFilesAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> var found = foundFiles.Count();</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This way is much more convenient to keep in sync items from some source and the indexed items. You only have to create a file every time an item is added and remove it at the right moment. You are able to perform the same operations you can do with the previous approach.</p> http://www.silverlightshow.net/items/Windows-8.1-The-Windows-Search-API.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-The-Windows-Search-API.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-The-Windows-Search-API.aspx Wed, 15 Jan 2014 11:40:00 GMT Windows 8.1: Create a PDF Viewer with new PDF API <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-8.1-Create-a-PDF-Viewer-with-new-PDF-API.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Create-a-PDF-Viewer-with-new-PDF-API.aspx" data-count="horizontal" data-text="Read @aboschin's article 'Windows 8.1: Create a PDF Viewer with new PDF API. #win8dev #win81" data-url="http://slshow.net/1gbj0Cy">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-8.1-Create-a-PDF-Viewer-with-new-PDF-API.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/XPG.PDFViewer.zip">Download the source code for this article</a></strong> </div> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Webinar recording: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">Portable Document Format is actually the de-facto standard for document publishing since it is widely adopted by all platforms and used by most of people. Supporting PDF is something that a platform cannot avoid and, since the very first release, Windows 8 comes with an app that can read this format. In the latest release the APIs gained a new namespace dedicated to the PDF format, so now you can easily read and operate with these files. What's the better example than create a little and simple PDF Viewer?</p> <h4 style="text-align: justify;">Windows.Data.Pdf</h4> <p style="text-align: justify;">The new API dedicated to the Portable Document Format are all in the Windows.Data.Pdf namespace. They are really simple and basic and only allows to read documents, so please, if your intent is to output a PDF from your app choose one of the free or commercial libraries available. </p> <p style="text-align: justify;">The root class in the namespace is PdfDocument that is able to read the content from a file (a IStorageFile instance) or directly from a stream enabling the manipulation of in-memory contents. Here is a simple example:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> StorageFile file = <span style="color: #0000ff;">this</span>.GetFile();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">this</span>.Document = await PdfDocument.LoadFromFileAsync(file);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The two static methods, LoadFromFileAsync and LoadFromStreamAsync both allow you to open password protected files providing the password as secondary argument. You only know that a document is protected by a password trying to open it so you have to catch the raised exception and then ask the user for the password.</p> <p style="text-align: justify;">Once the document has been loaded you have very few information about it. The PdfDocument class only provide the PageCount and a boolean flag set to true if the document is password protected. I would have preferred something more but that's it. </p> <p style="text-align: justify;">Of course you are able to get every single page as and instance of PdfPage class using the GetPage method that requires the index of the page to extract. The PdfPage class has some more information available including the size of the page, its index in the document and other properties like the rotation and dimensions. Here is how you can get the page:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> PdfPage page = <span style="color: #0000ff;">this</span>.Document.GetPage(1);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> var width = page.Size.Width;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> var height = page.Size.Height;</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">In the same snippet you also see how to get the current size of the page form the Size property. </p> <p style="text-align: justify;">Having a reference to a page is the starting point to render it to the view. The API lets you to render the page to a bitmap so you can then use an Image to display the content to the user. The rendering is almost simple:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> await <span style="color: #0000ff;">this</span>.CurrentPage.RenderToStreamAsync(stream);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This line is able to render the page to a stream in the PNG format. </p> <h4 style="text-align: justify;">Create a simple PDF reader</h4> <p style="text-align: justify;"><a href="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/___image_2.png"><img height="182" width="279" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/____image_thumb.png" alt="image" style="margin: 0px 0px 0px 15px; display: inline; float: right;" title="image" /></a>Before to go deep inside the rendering options that are someway much more powerful that the simple example I’ve provided in the previous snippet, let start a little project that will implement a basic PDF Viewer able to navigate the document and zoom in and out its pages. </p> <p style="text-align: justify;">First of all let start creating a blank application project with the structure in the figure on the right side. The application only contains a single page that is the surface where the PDF will be displayed. In a fully featured version you should implement share target contract and associate with the .pdf extension but for the purpose of this example I only added a button that allows to pick a pdf file from the file system. The other components are the image rendering surface (a Image element), two buttons used to navigate the pages and a text block to display the current position in the document.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <Grid Background=<span style="color: #006080;">"{ThemeResource ApplicationPageBackgroundThemeBrush}"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <Grid.Resources></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <Style TargetType=<span style="color: #006080;">"Button"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <Setter Property=<span style="color: #006080;">"BorderThickness"</span> Value=<span style="color: #006080;">"0"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> </Style></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> </Grid.Resources></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <Button x:Name=<span style="color: #006080;">"btnOpenFile"</span> Content=<span style="color: #006080;">"Click to open file"</span> VerticalAlignment=<span style="color: #006080;">"Stretch"</span> HorizontalAlignment=<span style="color: #006080;">"Stretch"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <Grid x:Name=<span style="color: #006080;">"grdView"</span> Visibility=<span style="color: #006080;">"Collapsed"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <Image x:Name=<span style="color: #006080;">"imgRenderSurface"</span> Stretch=<span style="color: #006080;">"Uniform"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <Border Background=<span style="color: #006080;">"{ThemeResource ApplicationPageBackgroundThemeBrush}"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> Padding=<span style="color: #006080;">"5"</span> VerticalAlignment=<span style="color: #006080;">"Top"</span> HorizontalAlignment=<span style="color: #006080;">"Center"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <TextBlock FontSize=<span style="color: #006080;">"24"</span> x:Name=<span style="color: #006080;">"txtPage"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> </Border></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <Button x:Name=<span style="color: #006080;">"btnBack"</span> HorizontalAlignment=<span style="color: #006080;">"Left"</span> VerticalAlignment=<span style="color: #006080;">"Center"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> Background=<span style="color: #006080;">"{ThemeResource ApplicationPageBackgroundThemeBrush}"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <SymbolIcon Symbol=<span style="color: #006080;">"Back"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> </Button></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <Button x:Name=<span style="color: #006080;">"btnForward"</span> HorizontalAlignment=<span style="color: #006080;">"Right"</span> VerticalAlignment=<span style="color: #006080;">"Center"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> Background=<span style="color: #006080;">"{ThemeResource ApplicationPageBackgroundThemeBrush}"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <SymbolIcon Symbol=<span style="color: #006080;">"Forward"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> </Button></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> </Grid></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> </Grid></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The flow starts when the user clicks the button to open the document. This will start the FileOpenPicker to let the user choose a single pdf file to open. When the file has been choosed the control passes to the OpenFile method that loads the PDF and initializes the rendering environment. Some properties like “ZoomFactor” are initialized but they will be used only in the next step, when I‘ll show how to implement zooming.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> btnOpenFile_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> FileOpenPicker picker = <span style="color: #0000ff;">new</span> FileOpenPicker();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> picker.FileTypeFilter.Add(<span style="color: #006080;">".pdf"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> StorageFile file = await picker.PickSingleFileAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">if</span> (file != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> await OpenFile(file);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">private</span> async Task OpenFile(StorageFile file)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">try</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">this</span>.Document = await PdfDocument.LoadFromFileAsync(file);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> } </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">catch</span>(Exception ex)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> MessageDialog dialog = <span style="color: #0000ff;">new</span> MessageDialog(ex.Message);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> dialog.ShowAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;">return</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;">this</span>.CurrentPageIndex = 0;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">this</span>.ZoomFactor = 1.0;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">this</span>.SetState(<span style="color: #0000ff;">false</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> await <span style="color: #0000ff;">this</span>.RenderPage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">After the file has been successfully opened, the flow call the RenderPage method that is the central core that renders the pdf to the image surface. The current version simply render the full page on the surface:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async Task RenderPage()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">this</span>.CurrentPage = <span style="color: #0000ff;">this</span>.Document.GetPage((<span style="color: #0000ff;">uint</span>)<span style="color: #0000ff;">this</span>.CurrentPageIndex);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">using</span> (IRandomAccessStream stream = <span style="color: #0000ff;">new</span> MemoryStream().AsRandomAccessStream())</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> await <span style="color: #0000ff;">this</span>.CurrentPage.RenderToStreamAsync(stream);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> BitmapImage source = <span style="color: #0000ff;">new</span> BitmapImage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> source.SetSource(stream);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> imgRenderSurface.Source = source;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">this</span>.txtPage.Text = <span style="color: #0000ff;">string</span>.Format(<span style="color: #006080;">"{0} of {1}"</span>, <span style="color: #0000ff;">this</span>.CurrentPageIndex + 1, <span style="color: #0000ff;">this</span>.Document.PageCount);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">First of all, the current page is loaded on the basis of the current page index. This is updated by the forward and backward buttons as I’ll show later. Then it is created a MemoryStream and casted to a IRandomAccessStream. This let you to write the content of the page to the stream using the RenderToStreamAsync method. In this way it is not required to create a temporary file on the file system to write the page before to load it in the Image element. Once the stream has been written, it is assigned to the Image element using a BitmapImage. This class is able to load content from the stream and then can be set as source for the image itself. </p> <p style="text-align: justify;">When the user hits the forward and backward buttons the code simply evaluate the updated current index and check that it is inside the boundaries of document PageCount. </p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> SwitchPage_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">if</span> (sender == <span style="color: #0000ff;">this</span>.btnBack && <span style="color: #0000ff;">this</span>.CurrentPageIndex > 0)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">this</span>.CurrentPageIndex--;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> await <span style="color: #0000ff;">this</span>.RenderPage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> (sender == <span style="color: #0000ff;">this</span>.btnForward && <span style="color: #0000ff;">this</span>.CurrentPageIndex < (<span style="color: #0000ff;">int</span>)<span style="color: #0000ff;">this</span>.Document.PageCount - 1)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">this</span>.CurrentPageIndex++;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> await <span style="color: #0000ff;">this</span>.RenderPage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> }</pre> <!--CRLF--></div> </div> </div> <h4 style="text-align: justify;">Implement a simple zoom </h4> <p style="text-align: justify;">The PdfPage class does not only allow to render pages to a PNG bitmap, but is also able to zoom and crop portions of the page and then render it to the bitmap without losing definition. PDF is a vector image format so you can simply determine the desired size and the rendering has always the better definition if the file does not contains embedded bitmap images. To implement zooming you can simply increase the output desired size setting the DestinationHeight and DestinationWidth properties on the PdfPageRenderOptions class. This class is made to change the default behavior of the rendering process and have a number of properties that influences how the rendering happens. Setting the two properties let you determine the size of the output bitmap and so the resulting image will be larger.</p> <p style="text-align: justify;">These properties can be used in junction with the SourceRect property that instead determine the portion of the page to render on the give size. In the following snippet I’ll use both the features to implement a “strange” zooming that is not the best for the user experience but let me show I a single piece of code how both cropping and zooming works together. Let start adding a bunch of buttons: </p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Orientation</span><span style="color: #0000ff;">="Horizontal"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Bottom"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Right"</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="{ThemeResource ApplicationPageBackgroundThemeBrush}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnZoomIn"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SymbolIcon</span> <span style="color: #ff0000;">Symbol</span><span style="color: #0000ff;">="ZoomIn"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnZoomOut"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SymbolIcon</span> <span style="color: #ff0000;">Symbol</span><span style="color: #0000ff;">="ZoomOut"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="grdPan"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Bottom"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.RowDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.RowDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnUp"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">ColumnSpan</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SymbolIcon</span> <span style="color: #ff0000;">Symbol</span><span style="color: #0000ff;">="Up"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnDown"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">ColumnSpan</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SymbolIcon</span> <span style="color: #ff0000;">Symbol</span><span style="color: #0000ff;">="Download"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnLeft"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="0"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SymbolIcon</span> <span style="color: #ff0000;">Symbol</span><span style="color: #0000ff;">="Back"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnRight"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SymbolIcon</span> <span style="color: #ff0000;">Symbol</span><span style="color: #0000ff;">="Forward"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">These are the zoom-in and zoom-out buttons together with 4 buttons used to pan the zoom on the whole page size. The zoom will always have the full page size but it will work as a keyhole on a portion of the page. The pan buttons let you move the hole on the entire surface:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> private async void Pan_Click(object sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> if (this.CurrentPage != null)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> double width = this.CurrentPage.Size.Width * (1 / this.ZoomFactor);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> double height = this.CurrentPage.Size.Height * (1 / this.ZoomFactor);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> double x = this.Position.X;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> double y = this.Position.Y;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> if (sender == this.btnUp)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> y -= height;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> if (y <span style="color: #0000ff;"><</span> 0) y = 0;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> else if (sender == this.btnLeft)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> x -= width;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> if (x <span style="color: #0000ff;"><</span> 0) x = 0;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> else if (sender == this.btnDown)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> y += height;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> if (y + height <span style="color: #0000ff;">></span> this.CurrentPage.Size.Height) </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> y = this.CurrentPage.Size.Height - height;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> else if (sender == this.btnRight)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> x += width;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> if (x + width <span style="color: #0000ff;">></span> this.CurrentPage.Size.Width) </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> x = this.CurrentPage.Size.Width - width;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> this.Position = new Point(x, y);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> await this.RenderPage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span> private async void ChangeZoom_Click(object sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span> if (sender == this.btnZoomOut && this.ZoomFactor <span style="color: #0000ff;">></span> 1.0)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> this.ZoomFactor -= .5;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> await this.RenderPage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum49" style="color: #606060;"> 49:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum50" style="color: #606060;"> 50:</span> else if (sender == this.btnZoomIn && this.ZoomFactor <span style="color: #0000ff;"><</span> 5.0)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum51" style="color: #606060;"> 51:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum52" style="color: #606060;"> 52:</span> this.ZoomFactor += .5;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum53" style="color: #606060;"> 53:</span> await this.RenderPage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum54" style="color: #606060;"> 54:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum55" style="color: #606060;"> 55:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum56" style="color: #606060;"> 56:</span> this.grdPan.Visibility = this.ZoomFactor <span style="color: #0000ff;">></span> 1 ? Visibility.Visible : Visibility.Collapsed;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum57" style="color: #606060;"> 57:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">After the button logic has been created it is time to change the RenderPage behavior. This now will crop a single piece of the page on the basis of the current zoom factor</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async Task RenderPage()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">this</span>.CurrentPage = <span style="color: #0000ff;">this</span>.Document.GetPage((<span style="color: #0000ff;">uint</span>)<span style="color: #0000ff;">this</span>.CurrentPageIndex);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">using</span> (IRandomAccessStream stream = <span style="color: #0000ff;">new</span> MemoryStream().AsRandomAccessStream())</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.ZoomFactor != 1)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> PdfPageRenderOptions options = <span style="color: #0000ff;">new</span> PdfPageRenderOptions();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> options.DestinationHeight = (<span style="color: #0000ff;">uint</span>)<span style="color: #0000ff;">this</span>.imgRenderSurface.ActualHeight;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> options.DestinationWidth = (<span style="color: #0000ff;">uint</span>)<span style="color: #0000ff;">this</span>.imgRenderSurface.ActualWidth;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">double</span> width = <span style="color: #0000ff;">this</span>.CurrentPage.Size.Width * (1 / <span style="color: #0000ff;">this</span>.ZoomFactor);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">double</span> height = <span style="color: #0000ff;">this</span>.CurrentPage.Size.Height * (1 / <span style="color: #0000ff;">this</span>.ZoomFactor);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> options.SourceRect = <span style="color: #0000ff;">new</span> Rect(<span style="color: #0000ff;">this</span>.Position, <span style="color: #0000ff;">new</span> Point(<span style="color: #0000ff;">this</span>.Position.X + width, <span style="color: #0000ff;">this</span>.Position.Y + height));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> await <span style="color: #0000ff;">this</span>.CurrentPage.RenderToStreamAsync(stream, options);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">else</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> await <span style="color: #0000ff;">this</span>.CurrentPage.RenderToStreamAsync(stream);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> BitmapImage source = <span style="color: #0000ff;">new</span> BitmapImage();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> source.SetSource(stream);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> imgRenderSurface.Source = source;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">this</span>.txtPage.Text = <span style="color: #0000ff;">string</span>.Format(<span style="color: #006080;">"{0} of {1}"</span>, <span style="color: #0000ff;">this</span>.CurrentPageIndex + 1, <span style="color: #0000ff;">this</span>.Document.PageCount);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The updated RenderPage method works differently when the ZoomFactor is different from 1.0 (no zoom). It then creates a PdfPageRenderOptions instance and set the DestinationWidth and DestinationHeight properties to the size of the whole page. Then, using the SourceRect it sets a rectangle of a reduced size, and the result is rendered to the image surface. This make the output image being a zoom of the source rectangle without losing in quality.</p> <h4 style="text-align: justify;">Try by yourself</h4> <p style="text-align: justify;">The example I presented is available for the download attached to this article. You can try by yourself the code I’ve talked about in the previous paragraphs. The Windows.Data.Pdf namespace will let you add some interesting features to your apps, but please do not expect so much from it since it is a very minimal toolset that I hope will be improved in future releases.</p> http://www.silverlightshow.net/items/Windows-8.1-Create-a-PDF-Viewer-with-new-PDF-API.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Create-a-PDF-Viewer-with-new-PDF-API.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Create-a-PDF-Viewer-with-new-PDF-API.aspx Mon, 06 Jan 2014 12:14:00 GMT Windows 8.1: Alarm and Lock screen call toasts <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-8.1-Alarm-and-Lock-screen-call-toasts.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/IZm9tD" data-text="Read @aboschin's article 'Windows 8.1: Alarm & Lock screen call toasts. #win8dev #win81" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Alarm-and-Lock-screen-call-toasts.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-8.1-Alarm-and-Lock-screen-call-toasts.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/XPG.ToastNotifications.zip">Download the source code for this article</a></strong> </div> <p style="text-align: justify;">In Windows 8.1, the notification system has got some new improvements that make it much more flexible. Since the very first relase you have been able to send different typer of notifications called badges, toasts and tiles. These notifications let you interact with the user from the running application and also from a background task, allowing the application to notify messages when it is not running. </p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Webinar recording: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">Starting from the latest relase the toast notifications have got  some new interesting features. When the user is notified he can not only dismiss the notification or open the application by clicking the toast, but he can also use a number of predefined commands, presented by the application in specific scenarios. Let start explore the alarm scheduling scenario:</p> <h4 style="text-align: justify;">Send alarm toasts</h4> <p style="text-align: justify;">The most simple form of notification, added to this release, is made to emulate an alarm clock. This kind of notification should be raised to notify a scheduled event and it allows to add two additional button, the first to dismiss the notification and the second to snooze the alarm.</p> <p style="text-align: justify;">As usual, presenting a toast notification means compiling a short chunk of xml. This is because the notifications are designed to be send over a network channel when they are raised by a push notification system. Here is the xml that is composed by the app to send an alarm notification:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">toast</span> <span style="color: #ff0000;">duration</span><span style="color: #0000ff;">="long"</span> <span style="color: #ff0000;">launch</span><span style="color: #0000ff;">="alarm(eb6c47a8-e5e2-40d0-bc4e-3aa957f36484)"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">visual</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">binding</span> <span style="color: #ff0000;">template</span><span style="color: #0000ff;">="ToastImageAndText04"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">text</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span>Silverlight Show<span style="color: #0000ff;"></</span><span style="color: #800000;">text</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">text</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="2"</span><span style="color: #0000ff;">></span>New article by A. Boschin<span style="color: #0000ff;"></</span><span style="color: #800000;">text</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">text</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="3"</span><span style="color: #0000ff;">></span>Windows 8.1: Alarm and Lock screen call toasts<span style="color: #0000ff;"></</span><span style="color: #800000;">text</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">image</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">="ms-appx:///Assets/SilverlightShow.png"</span> <span style="color: #ff0000;">alt</span><span style="color: #0000ff;">="hallo"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">binding</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">visual</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">audio</span> <span style="color: #ff0000;">loop</span><span style="color: #0000ff;">="true"</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">="ms-winsoundevent:Notification.Looping.Alarm2"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">commands</span> <span style="color: #ff0000;">scenario</span><span style="color: #0000ff;">="alarm"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">command</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="snooze"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">command</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="dismiss"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">commands</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">toast</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The notification xml is divided in three parts:</p> <p style="text-align: justify;"><strong>visual</strong>: it contains the visual aspect of the notification. It can be selected between 8 different templates you can see on this page. <a title="http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx" href="http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx">http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx</a> The showed xml is the most complex that contains three lines of text (the first one in bold) and an image of 90x90 pixels. </p> <p style="text-align: justify;"><strong>audio</strong>: it describes the sound to be played when the notification appears. It can assume a number of predefined sounds that are listed in this page: <a title="http://msdn.microsoft.com/en-us/library/windows/apps/br230842.aspx" href="http://msdn.microsoft.com/en-us/library/windows/apps/br230842.aspx">http://msdn.microsoft.com/en-us/library/windows/apps/br230842.aspx</a></p> <p style="text-align: justify;"><strong>commands</strong>: this is the most important section that determines the scenarion (in this case "alarm") and the enabled commands. They must be "snooze" or "dismiss" for alarm notifications.</p> <p style="text-align: justify;">Once you compiled the xml it is time to send it to the notification system. In this scenario I'll use a ScheduledToastNotification that allows to specify some parameters that apply to the given commands. </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> NotifyScheduled(<span style="color: #0000ff;">string</span> toast, <span style="color: #0000ff;">int</span> delay = 5, <span style="color: #0000ff;">int</span> snooze = 300, <span style="color: #0000ff;">int</span> maxSnoozeCount = 3)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> XmlDocument document = <span style="color: #0000ff;">new</span> XmlDocument();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> document.LoadXml(toast);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> var notifier = ToastNotificationManager.CreateToastNotifier();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> var scheduledToast = <span style="color: #0000ff;">new</span> ScheduledToastNotification(document, DateTime.Now.AddSeconds(delay), TimeSpan.FromSeconds(snooze), (<span style="color: #0000ff;">uint</span>)maxSnoozeCount);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> notifier.AddToSchedule(scheduledToast);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">In the first line the xml is converted to a XmlDocument instance. It is because the ToastNotification require this type. After the xml has been parsed, using the ToastNotificationManager it is created an instance of a notifier, responsible to communicate with the notification system. Then the code creates the scheduled notification passing as arguments the date and time of the alarm, the snooze timeout and the max number of snoozes it allows (0 means infinite). The notification is then added to the notifier.</p> <p style="text-align: justify;"><img width="566" height="99" title="Capture" style="margin: 5px 0px 0px 15px; border: 0px none currentcolor; display: inline; background-image: none; float: right;" alt="Capture" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/_______Capture.png" />This code cause the appearance of the following notification, after a couple of seconds (the delay): </p> <p style="text-align: justify;">The two buttons in the figure corresponds to the commands that has been send to the notifier. They act automatically without the needs of intervention by the developer code. </p> <p style="text-align: justify;">The sole thing you have to be aware is that the manifest should be modified partially with the designer and partially by hand. You have to create a dummy background task (no code required) to allow the app to run when it is closed. In a real world application this task should work to collect notification and schedule notifications. Here a snippet from the manifest:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Extensions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Extension</span> <span style="color: #ff0000;">Category</span><span style="color: #0000ff;">="windows.backgroundTasks"</span> <span style="color: #ff0000;">EntryPoint</span><span style="color: #0000ff;">="SamplePlaceholder"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">BackgroundTasks</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Task</span> <span style="color: #ff0000;">Type</span><span style="color: #0000ff;">="audio"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Task</span> <span style="color: #ff0000;">Type</span><span style="color: #0000ff;">="timer"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">BackgroundTasks</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Extension</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:Extension</span> <span style="color: #ff0000;">Category</span><span style="color: #0000ff;">="windows.alarm"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Extensions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The "windows.alarm" category has to be added manually because it is not supported by the designer.</p> <h4 style="text-align: justify;">Handle incoming calls</h4> <p style="text-align: justify;">Many applications are currently made to communicate each other. In these days the traditional phone call and text messages have been often passed by applications like skype and whatsapp that give better features for free or at a lower rate. This requires that the application framework directly supports these new scenarios and accept a new kind of notification that is able to notify an incoming call. Windows 8.1 accepted the challenge in this scenario so they added a new kind of toast notifications, able to work in lock screen applications that enable the developers to present notifications to the user and receive the choosen options as answer. </p> <p style="text-align: justify;">As for alarm notifications, the lock screen calls are made of a brief chunk of xml. It is presented in the following snippet:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">toast</span> <span style="color: #ff0000;">duration</span><span style="color: #0000ff;">="long"</span> <span style="color: #ff0000;">launch</span><span style="color: #0000ff;">="ls(60129d07-a1af-4b53-840b-669d09f1c013)"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">visual</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">binding</span> <span style="color: #ff0000;">template</span><span style="color: #0000ff;">="ToastImageAndText04"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">text</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span>Silverlight Show calling<span style="color: #0000ff;"></</span><span style="color: #800000;">text</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">text</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="2"</span><span style="color: #0000ff;">></span>A new call is incoming<span style="color: #0000ff;"></</span><span style="color: #800000;">text</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">text</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="3"</span><span style="color: #0000ff;">></span>You can answer the call in voice or video...<span style="color: #0000ff;"></</span><span style="color: #800000;">text</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">image</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">="ms-appx:///Assets/SilverlightShow.png"</span> <span style="color: #ff0000;">alt</span><span style="color: #0000ff;">="hallo"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">binding</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">visual</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">audio</span> <span style="color: #ff0000;">loop</span><span style="color: #0000ff;">="true"</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">="ms-winsoundevent:Notification.Looping.Call3"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">commands</span> <span style="color: #ff0000;">scenario</span><span style="color: #0000ff;">="incomingCall"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">command</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="decline"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">command</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="video"</span> <span style="color: #ff0000;">arguments</span><span style="color: #0000ff;">="Incoming Video Call"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">command</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="voice"</span> <span style="color: #ff0000;">arguments</span><span style="color: #0000ff;">="Incoming Voice Call"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">commands</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">toast</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p style="text-align: justify;">The sections in the xml are exactly the same as in alarm notifications. the sole difference are in the scenario's name that is "incomingCall" and in the commands. The commands for an incoming call includes "decline" to close the call without an answer, "voice" to accept the voice call or "video" to accept both voice and video parts of the call. In these two commands you can specify an argument that will be used by the application to understand how to operate with the user's choice. </p> <p style="text-align: justify;">The provided snippet will show a toast notification like the following:</p> <p style="text-align: justify;"><img width="658" height="98" title="Capture1" style="margin: 5px 0px 0px; border: 0px none currentcolor; display: inline; background-image: none; float: right;" alt="Capture1" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/____Capture1.png" /></p> <p style="text-align: justify;"> </p> <p style="text-align: justify;"> </p> <p style="text-align: justify;"> </p> <p style="text-align: justify;"> </p> <p style="text-align: justify;"> </p> <p style="text-align: justify;"> </p> <p style="text-align: justify;">Of course you are not required to specify both the commands "video" and "voice" but you can tailor the needed commands on the basis of the features of your applications. You can also omit to specify the "decline" command and it will not be showed in the toast, but the user can always dismiss the notification with the well known gestures.</p> <p style="text-align: justify;">To raise the notification you can use a simplified version of the code presented for alarm notifications. The following snippet show the code required:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> NotifyImmediate(<span style="color: #0000ff;">string</span> toast)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> XmlDocument document = <span style="color: #0000ff;">new</span> XmlDocument();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> document.LoadXml(toast);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> var notifier = ToastNotificationManager.CreateToastNotifier();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> var scheduledToast = <span style="color: #0000ff;">new</span> ToastNotification(document);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> notifier.Show(scheduledToast);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--></div> </div> <p style="text-align: justify;">I think the code is so simple and it does not requires a detailed explanation. Once you have setup the commands and raised the notification you probably would want to get a notification when the user clicks one of the commands. This is done using the OnLaunched event in the App.xaml.cs. In the following snippet I show the simple code required to handle the incoming call:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">protected</span> async <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnLaunched(LaunchActivatedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #008000;">// ...initialization here...</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">string</span>.IsNullOrEmpty(e.Arguments))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> rootFrame.Navigate(<span style="color: #0000ff;">typeof</span>(NotificationPage), e.Arguments);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #008000;">// Ensure the current window is active</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> Window.Current.Activate();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--></div> </div> <h4 style="text-align: justify;">A toolkit to generate toast xml</h4> <p style="text-align: justify;">There are a number of ways to compile the xml required to send a notification, you can simply concatenate a string (no, I do not suggest to take this in serious consideration), you can use a XDocument object or you can create a number of types to be serialized to the required xml format. In the download provided with the article you will find a portable class library called XPG.ToastToolkit.dll that contains a useful object model and utility classes that let you generate easily the xml toast. You can write a code similar to the following to send an alarm notification:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> bAlarm_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Toast toast = <span style="color: #0000ff;">new</span> Toast</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> Duration = <span style="color: #006080;">"long"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> Launch = <span style="color: #006080;">"alarm("</span> + Guid.NewGuid().ToString() + <span style="color: #006080;">")"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> Audio = <span style="color: #0000ff;">new</span> ToastAudio { Loop = <span style="color: #0000ff;">true</span>, Source = <span style="color: #006080;">"ms-winsoundevent:Notification.Looping.Alarm2"</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Visual = <span style="color: #0000ff;">new</span> ToastVisual</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> Binding = <span style="color: #0000ff;">new</span> ToastImageAndText04Binding</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> Text1 = <span style="color: #006080;">"Silverlight Show"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> Text2 = <span style="color: #006080;">"New article by A. Boschin"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> Text3 = <span style="color: #006080;">"Windows 8.1: Alarm and Lock screen call toasts"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> Image1 = <span style="color: #0000ff;">new</span> ToastImage { AltText = <span style="color: #006080;">"hallo"</span>, Source = <span style="color: #0000ff;">new</span> Uri(<span style="color: #006080;">"ms-appx:///Assets/SilverlightShow.png"</span>) }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> Scenario = <span style="color: #0000ff;">new</span> Alarm</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> CanDismiss = <span style="color: #0000ff;">true</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> CanSnooze = <span style="color: #0000ff;">true</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">this</span>.NotifyScheduled(toast);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> }</pre> <!--CRLF--></div> </div> <p style="text-align: justify;">All the work is made inside the Toast class and the inner hierarchy. Feel free to use it in your applications.</p> http://www.silverlightshow.net/items/Windows-8.1-Alarm-and-Lock-screen-call-toasts.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Alarm-and-Lock-screen-call-toasts.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Alarm-and-Lock-screen-call-toasts.aspx Mon, 16 Dec 2013 12:07:00 GMT Windows 8.1: Improved device interactions <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-8.1-Improved-device-interactions.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Improved-device-interactions.aspx" data-count="horizontal" data-text="Read @aboschin's article 'Windows 8.1: Improved device interactions. #win8dev #win81" data-url="http://slshow.net/1cgPAT0">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-8.1-Improved-device-interactions.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/XPG.DeviceInteraction.zip">Download the source code for this article</a></strong> </div> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Webinar recording: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">When developing for a traditional computer, we are use to almost completely forget the environment where we are running. Usually each application works without being aware of other software installed and of device services like an address book or a calendar. This is different in Windows 8, when you run inside the Windows Runtime, where you can share between applications using contracts and you can rely on some baseline services that provide a uniform usability to the user.  In Windows 8.1 you gain some new features in this area, that let you being much more in contact with the underlying operating system and provide a better user experience.</p> <h4 style="text-align: justify;">Appointments and Contacts</h4> <p style="text-align: justify;">In Windows 8 the interaction with the calendar and address book of the device was really basic. It only allowed to add, update and remove contacts from the address book. In the new version of the operating system it is now also possible to manage appointments as well as the contacts, but you are also able to write a replacement application for the default calendar application. This not only means you can manage appointments invoking the system application, but also you can completely rewrite the system application to manage appointments and being invoked by other apps for appointment actions. Let examine the following snippet of code: </p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">string</span> id;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> AddAppointment_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> Appointment appointment = <span style="color: #0000ff;">new</span> Appointment();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> appointment.Subject = <span style="color: #006080;">"Going to cut my hairs"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> appointment.Location = <span style="color: #006080;">"Venice"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> appointment.StartTime = <span style="color: #0000ff;">new</span> DateTimeOffset(2013, 12, 5, 17, 0, 0, TimeSpan.FromHours(1));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> appointment.Duration = TimeSpan.FromHours(1);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> var buttonRect = <span style="color: #0000ff;">this</span>.GetElementRect((FrameworkElement)sender);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">this</span>.id = await AppointmentManager.ShowAddAppointmentAsync(appointment, buttonRect, Windows.UI.Popups.Placement.Below);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">string</span>.IsNullOrEmpty(id))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> MessageDialog dialog = <span style="color: #0000ff;">new</span> MessageDialog(<span style="color: #0000ff;">this</span>.id);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> await dialog.ShowAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">With this simple code we are able to invoke the default calendar application to ask to add a new appointment. The appointment we are about to add is very simple, made only of a subject, a location, a start time and a duration. These are only some of a huge number of properties we are able to set when we add an appointment. </p> <p style="text-align: justify;"><img width="249" height="370" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_e917bcfe-9ad0-46f4-98c6-253b721b3445.png" alt="image" style="margin: 5px 0px 0px 15px; border: 0px none currentcolor; display: inline; background-image: none; float: right;" title="image" /></p> <p style="text-align: justify;">The other properties also include the Details, BusyStatus, Reminder, Sensitivity, an associated Url, and also details about organizer and invitees and invitations. These are the common properties you are use to set when you create an appointment in a modern calendar application like outlook.  With this code, the system is invoked and it will open a popup where it is shown the ui provided by the default application. The image on the right side shows the resulting popup. </p> <p style="text-align: justify;">As a result of the operation you can get an empty string meaning that the popup has been dismissed without adding any appointments or the unique identifier of the appointment.</p> <p style="text-align: justify;">With this identifier you are able to invoke replacement or deletion of existing appointment. These operations also show a popup that ask the confirmation of the operation, with details about the appointment that is about to be replaced or deleted. When you replace an appointment the identifier of the new appointment is the same as the previous appointment but always rely to the returned id because the behavior may be different when the default application is replaced by a custom application.</p> <p style="text-align: justify;">Finally you can also invoke the calendar to show a specific timeframe, to enable your user to scan for free slots to assign to new appointmente. In this case the UI will not be invoked in a popup but will be opened on an half of the screen. Here is a snippet of code to show how to invoke these other operations.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> RemoveAppointment_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> var buttonRect = <span style="color: #0000ff;">this</span>.GetElementRect((FrameworkElement)sender);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> await AppointmentManager.ShowRemoveAppointmentAsync(<span style="color: #0000ff;">this</span>.id, buttonRect);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> ReplaceAppointment_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> Appointment appointment = <span style="color: #0000ff;">new</span> Appointment();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> appointment.Subject = <span style="color: #006080;">"Going to cut my hairs AGAIN!"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> appointment.Location = <span style="color: #006080;">"Venice"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> appointment.StartTime = <span style="color: #0000ff;">new</span> DateTimeOffset(2013, 12, 5, 18, 0, 0, TimeSpan.FromHours(1));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> appointment.Duration = TimeSpan.FromHours(1);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> var buttonRect = <span style="color: #0000ff;">this</span>.GetElementRect((FrameworkElement)sender);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">this</span>.id = await AppointmentManager.ShowReplaceAppointmentAsync(<span style="color: #0000ff;">this</span>.id, appointment, buttonRect);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">string</span>.IsNullOrEmpty(id))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> MessageDialog dialog = <span style="color: #0000ff;">new</span> MessageDialog(<span style="color: #0000ff;">this</span>.id);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> await dialog.ShowAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> ShowTimeframe_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> await AppointmentManager.ShowTimeFrameAsync(<span style="color: #0000ff;">new</span> DateTimeOffset(2013, 12, 5, 18, 0, 0, TimeSpan.FromHours(1)), TimeSpan.FromHours(1));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">As I've anticipated, you can also provide your own calendar application and being active in the other side of the calls I've described in the previous paragraphs. This means you can wrap up your own company calendar with a custom application and make it automatically handled by the device and invoked by each application that need to add/remove appointments. For this purpose you have to add the following code to your application's manifest:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Extensions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:Extension</span> <span style="color: #ff0000;">Category</span><span style="color: #0000ff;">="windows.appointmentsProvider"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:AppointmentsProvider</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:AppointmentsProviderLaunchActions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:LaunchAction</span> <span style="color: #ff0000;">Verb</span><span style="color: #0000ff;">="addAppointment"</span> <span style="color: #ff0000;">EntryPoint</span><span style="color: #0000ff;">="XPG.DeviceInteraction.App"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:LaunchAction</span> <span style="color: #ff0000;">Verb</span><span style="color: #0000ff;">="replaceAppointment"</span> <span style="color: #ff0000;">EntryPoint</span><span style="color: #0000ff;">="XPG.DeviceInteraction.App"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:LaunchAction</span> <span style="color: #ff0000;">Verb</span><span style="color: #0000ff;">="removeAppointment"</span> <span style="color: #ff0000;">EntryPoint</span><span style="color: #0000ff;">="XPG.DeviceInteraction.App"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:LaunchAction</span> <span style="color: #ff0000;">Verb</span><span style="color: #0000ff;">="showTimeFrame"</span> <span style="color: #ff0000;">EntryPoint</span><span style="color: #0000ff;">="XPG.DeviceInteraction.App"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:AppointmentsProviderLaunchActions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:AppointmentsProvider</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:Extension</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Extensions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This block should be inserted into the Application tag, be only sure you have defined the "m2" namespace as the following uri: <a href="http://schemas.microsoft.com/appx/2013/manifest" title="http://schemas.microsoft.com/appx/2013/manifest">http://schemas.microsoft.com/appx/2013/manifest</a>. Each LaunchAction is related to the verb you want to handle and will cause your application to be activated with the ActivationKind equals to <em>AppointmentsProvider</em>. The area of the popup will be an application view that hosts a completely new instance of your application.</p> <p style="text-align: justify;">Managing appointments also means the need to query contacts - as an example to choose invitees for an event - but this is already supported by the previous Windows 8 api. In this release they add a new feature that lets you answer to contact actions. Contact actions are the one shown when you search a contact and you are presented with a number of buttons related to the information of the contact. A simple action could be the call to its phone number, the mapping of its address, the composition of a mail message when the contact exposes a mail address, etc...</p> <p style="text-align: justify;">Again to enable this feature you have to manually change the package manifest:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Extensions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Extension</span> <span style="color: #ff0000;">Category</span><span style="color: #0000ff;">="windows.protocol"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Protocol</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="tel"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Extension</span><span style="color: #0000ff;">></span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:Extension</span> <span style="color: #ff0000;">Category</span><span style="color: #0000ff;">="windows.contact"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:Contact</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:ContactLaunchActions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:LaunchAction</span> <span style="color: #ff0000;">Verb</span><span style="color: #0000ff;">="call"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:ServiceId</span><span style="color: #0000ff;">></span>telephone<span style="color: #0000ff;"></</span><span style="color: #800000;">m2:ServiceId</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:LaunchAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:LaunchAction</span> <span style="color: #ff0000;">Verb</span><span style="color: #0000ff;">="message"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:ServiceId</span><span style="color: #0000ff;">></span>skype.com<span style="color: #0000ff;"></</span><span style="color: #800000;">m2:ServiceId</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:LaunchAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:LaunchAction</span> <span style="color: #ff0000;">Verb</span><span style="color: #0000ff;">="map"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:ContactLaunchActions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:Contact</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:Extension</span><span style="color: #0000ff;">></span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Extensions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The declaration for the "tel" protocol will handle the call to PSTN numbers but the additional extensions will handle the activation for other type of actions like skype calls, messages and mapping. As for the appointments activation these should be handled in the OnLaunch and OnActivated events of the application where you will receive an ActivationKind of type Contact.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnActivated(IActivatedEventArgs args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">if</span> (args.Kind == ActivationKind.Contact)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> var contactArgs = args <span style="color: #0000ff;">as</span> IContactActivatedEventArgs;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">if</span> (contactArgs.Verb == Windows.ApplicationModel.Contacts.ContactLaunchActionVerbs.Map)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> IContactMapActivatedEventArgs mapArgs = contactArgs <span style="color: #0000ff;">as</span> IContactMapActivatedEventArgs;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">this</span>.ActivateForContact(mapArgs.Contact, mapArgs.Address);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> ActivateForContact(Contact contact, ContactAddress contactAddress)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #008000;">// TODO: Activate here the required page</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> }</pre> <!--CRLF--></div> </div> </div> <h4 style="text-align: justify;">Interact with libraries</h4> <p style="text-align: justify;">Another interesting feature, that should give much more value to your apps is the ability of manage libraries. A library is a folder that contains items of the same type. They can be Pictures, Video, Music and Documents. With this new feature, you application can ask to add a folder to one of these libraries and be able to manage files inside of it. The first thing to do is to take a reference to the library you need to work with:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> StorageLibrary library = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Documents);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Once you get a reference to the library you are able to add and remove a folder. this shows the system picker that let you choose the existing folder, also if it is hosted in skydrive. The folder then, is completely under your control and you can create and remove files. Here is a snippet that show a complete activity:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> StorageLibraryAdd_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">try</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> StorageLibrary library = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Documents);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> StorageFolder folder = await library.RequestAddFolderAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #008000;">// check if user canceled</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">if</span> (folder != <span style="color: #0000ff;">null</span>) </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> StorageFile file = await folder.CreateFileAsync(<span style="color: #006080;">"document.txt"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">using</span> (StreamWriter writer = <span style="color: #0000ff;">new</span> StreamWriter(await file.OpenStreamForWriteAsync()))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> writer.WriteLine(<span style="color: #006080;">"this is a text document..."</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;">catch</span>(Exception ex)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> MessageDialog dialog = <span style="color: #0000ff;">new</span> MessageDialog(ex.Message);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> dialog.ShowAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Be aware that wher you call the RequestAddFolderAsync method, it can return a null value meaning the user canceled the addition. </p> <p style="text-align: justify;">To enable the access to the libraries you ar requested to add a capability to the manifest, from the editor. Remember that, if you need to access the Documents library you also have to add a file association to associate the files you create with your application . </p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;"><!-- file association --></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Extension</span> <span style="color: #ff0000;">Category</span><span style="color: #0000ff;">="windows.fileTypeAssociation"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FileTypeAssociation</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="txt"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DisplayName</span><span style="color: #0000ff;">></span>Text<span style="color: #0000ff;"></</span><span style="color: #800000;">DisplayName</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">EditFlags</span> <span style="color: #ff0000;">OpenIsSafe</span><span style="color: #0000ff;">="true"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SupportedFileTypes</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FileType</span> <span style="color: #ff0000;">ContentType</span><span style="color: #0000ff;">="text/plain"</span><span style="color: #0000ff;">></span>.txt<span style="color: #0000ff;"></</span><span style="color: #800000;">FileType</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">SupportedFileTypes</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">FileTypeAssociation</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Extension</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #008000;"><!-- capabilities --></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capabilities</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="internetClient"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="picturesLibrary"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="musicLibrary"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="videosLibrary"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="documentsLibrary"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Capabilities</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <h4 style="text-align: justify;">Manage the touch keyboard</h4> <p style="text-align: justify;">When you are on a touch device, without a mouse, the operating system tries to automatically popup the touch keyboard when you enter a textbox, because this means you need to type some characters. Until today only the text input elements are enabled to cause the touch keyboard to be showed, but there are cases when you may need to enter some text, also if you have not any textbox. For Windows 8.1 this is now possible using the automation helpers that associate to an arbitray item the requirements to have the touch keyboard opened. </p> <p style="text-align: justify;">Given you created a control, also an user control, the first thing is to create an automation peer. Implementing an automation peer is not a very simple thing. It is a class that implements a number of interfaces - in this case it implement ITextProvider and IValueProvider together with the FrameworkElementAutomationPeer base class - to provide services related to the behavior of the interface in the environment. Once the provider has been created - with all its logic and eventually nested classes - you must override the OnCreateAutomationPeer method in the control and return an instance of the automation peer:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> CustomTextInputAutomationPeer(<span style="color: #0000ff;">this</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">After this has been accomplished (I'll attach a project containig a base automation peer created using MSDN samples as a track), you must ensure the focus is set to your control. This means hook the OnTapped event and set the focus to the control. Once the focus had been set, the automation peer makes the work causing the touch keyboard to be showed up. Here is the full code of the user control:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">sealed</span> <span style="color: #0000ff;">partial</span> <span style="color: #0000ff;">class</span> CustomTextInput : UserControl</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">public</span> CustomTextInput()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">this</span>.InitializeComponent();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">this</span>.IsTapEnabled = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">this</span>.IsTabStop = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">this</span>.Text = <span style="color: #0000ff;">string</span>.Empty;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> CustomTextInputAutomationPeer(<span style="color: #0000ff;">this</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnTapped(TappedRoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">this</span>.Focus(Windows.UI.Xaml.FocusState.Pointer);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Text { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Obviously you can then get touch inputs using KeyDown event in the control. Beautiful feature, but I would like something much more simple and straightforward... </p> <h4 style="text-align: justify;">Conclusion</h4> <p style="text-align: justify;">In this article I talked about some new features that may sounds trivial, but as an careful exam they are really powerful to give a better feedback to your user. Besides the touch keyboard that requires a lot of work to implement a complex automation peer, alle of them are easy to be implemented and should be taken in serious consideration every time you need to develop a new app.</p> http://www.silverlightshow.net/items/Windows-8.1-Improved-device-interactions.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Improved-device-interactions.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Improved-device-interactions.aspx Mon, 02 Dec 2013 11:41:00 GMT Windows 8.1: Application Views improvements <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-8.1-Application-Views-improvements.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/184mK3G" data-text="Read @aboschin's article 'Windows 8.1: Application Views improvements. #win8dev #win81" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Application-Views-improvements.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-8.1-Application-Views-improvements.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Webinar recording: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p>To me, one of the most useful features in Windows 8 is the application's snapping which lets me to see up to two applications at the same time on the screen. On my tablet and in the desktop there are often reasons to snap an application on the side (e.g. skype is a good candidate for snapping) and continue to work, on the main screen, with the desktop or another application. In the first release of Windows 8 this feature is still limited by some constraints. You can snap only one application (for a total of 2 side by side) and the snapped app is always 320 pixel wide, no matter the size of your monitor.</p> <p>With Windows 8.1 these constraints have been changed to improve the snapping. Depending on the size of the screen you can now snap up to 4 applications and the size is now freely decided using a splitter between the applications. These improvements required some new features to be added to the developer toolset and in this article I'll show you the magic around the improved Application View management.</p> <h4>Application View and the basics</h4> <p>Application Views is the object that lets you manage the area where the application is hosted. It exists since the very first release of the operationg system, but due to the new improvements in this field, it has gained a set of new functions. To get an instance of the current application view you have to use the GetForCurrentView method as shown below. </p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var applicationView = ApplicationView.GetForCurrentView();</pre> <!--CRLF--></div> </div> <p>Differently from the previous version, where the static class only exposed the current state, this instance, which directly refers to the area of the current application, contains a number of useful properties. The Id is an unique identifier directly related to a new feature which I'll discuss in the next part of the article and the same is for Title that lets you give (and read) a title for the view that will be shown, for example, in the thumbnail list of running apps that appears when you swipe the left side of the screen. Other useful properties are related to the current state of the application: </p> <ul> <li><strong>AdjacentToLeftDisplayEdge</strong> and <strong>AdjacentToRightDisplayEdge</strong>: these properties inform if the view is currently snapped and is adiacent to one of the screen edges. It is useful to dock controls according to the detected position.</li> <li><strong>IsFullScreen</strong>: it is true when the app fills the entire screen.</li> <li><strong>IsOnLockScreen</strong>: this inform if the application is no the lock screen of Windows</li> <li><strong>IsScreenCaptureEnabled</strong>: this read/write property allows to prevent the user to take screenshoots of the application canvas. This let you protect your rights from unwanted copies and disclosures.</li> <li><strong>TerminateAppOnFinalViewClose</strong>: This property determines if the application should terminate when its last view is closed.</li> <li><strong>Orientation</strong>: As expected you can also detect the current orientation of the screen between Landscape and Portrait.</li> </ul> <p>The important to know is that the application view does not have nothing to do with the current page. It is much more related to the container of the pages. As a consequence you can take a reference to the application view once and use it in all the pages of the application. Please note that the property ApplicationView.Value has been deprecated and should not be used.</p> <p>To dinamically handle the application view changes you should rely on Windws size changes. This event is raised also when the orientation changes or when the view is resized because of a snapping or unsnapping. Thanks to this you can update the application layout according to a combination of the values of these properties:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">sealed</span> <span style="color: #0000ff;">partial</span> <span style="color: #0000ff;">class</span> MainPage : Page</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> ApplicationView ApplicationView { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">public</span> MainPage()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">this</span>.InitializeComponent();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">this</span>.ApplicationView = ApplicationView.GetForCurrentView();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> Window.Current.SizeChanged += Current_SizeChanged;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnNavigatedTo(NavigationEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">this</span>.UpdateVisualState();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">base</span>.OnNavigatedTo(e);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Current_SizeChanged(<span style="color: #0000ff;">object</span> sender, Windows.UI.Core.WindowSizeChangedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;">this</span>.UpdateVisualState();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> UpdateVisualState()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">this</span>.txtView.Text = <span style="color: #0000ff;">this</span>.ApplicationView.Orientation.ToString();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> }</pre> <!--CRLF--></div> </div> <h4>Working with multiple views</h4> <p>One new and interesting feature that comes with Window 8.1 is the capability to open multiple views from a single application. This is someway similar to spawning multiple windows in a desktop application but these does not appears in popup. The additional views instead are snapped or also they can fill the entire screen and hide the main application view. As the proof of fact the spawned application views work like an autonomous application. </p> <p>To create a new aplication view you have to use the CoreApplication class paying attention to the context of the thread where you work. This infact determine the scope of the Window.Current property that you can use to initialize the new view. Here is a simple snippet that creates a new view:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async System.Threading.Tasks.Task<<span style="color: #0000ff;">int</span>> CreateNewView()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> CoreApplicationView newView = CoreApplication.CreateNewView();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">int</span> newViewId = 0;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> await newView.Dispatcher.RunAsync(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> CoreDispatcherPriority.Normal,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> Frame frame = <span style="color: #0000ff;">new</span> Frame();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> frame.Navigate(<span style="color: #0000ff;">typeof</span>(SecondaryPage));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> Window.Current.Content = frame;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> newViewId = ApplicationView.GetForCurrentView().Id;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;">return</span> newViewId;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> }</pre> <!--CRLF--></div> </div> <p>As you can see, after having create the view with you need to attach its dispatcher to synchronize to its thread. When the labda is called you are in the context of the new view thread and the Window.Current points to the new application view Window. So, as you do usually in the app.xaml.cs you can creae a new frame and navigate to a page. Also pay attention that the call to GetForCurrentView here points to the new view so its Id is returned to the main thread. </p> <p>After this code has run the view has been created and initialized but it is still hidden. To display the view you have to activate it using the ApplicationViewSwitcher class. It suffice a simple line of code:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">bool</span> shown = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId, ViewSizePreference.UseLess);</pre> <!--CRLF--></div> </div> <p>The TryShowAsStandaloneAsync method gets the id of the view and a parameter that determines its initial size. This method has a numer of overloads that are useful to position the new view. In these overloads you can detemine not only the size of the new view but also the size of the exiting one. A combination of ViewSizePreference lets you make the main view small and the new one big or instead make them divide the space half and half. Do your tryies to get the result that mostly respect your needs.</p> <p>Then, you may need to close the secondary view. This is done using the SwitcAsync method in the ApplicationViewSwitcher that let you move between the views. You always have to specify the destination view and the starting view together with a parameter that says how to the switch behaves. Using the ConsolidateViews switch you ask the system to close the from view. This also means you are destroying the view and it should be removed from your management constructs.</p> <h4>Animate the transitions</h4> <p>Additional application views are for sure an interesting opportunity for the cases where you need to simulate multi-document application, having secondary view spawned in answer to different documents opened. This way you can create a single logic handling a document and then create a new view and start this logic with a reference with the document itself. </p> <p>Give that we are in a Windows Store app that, by definition, should be graphically appealing, fast and fluid as the pillar says, the team added the capability to use animations to make the switch between views someway much more fluid and beautiful. The sole support to this feature is from a method called "PrepareForCustomAnimatedSwitchAsync" that simply acquires the same parameters of TryShowAsStandaloneAsync, but simply prepares the ui to a subsequent switch of view. The whole animation must be handled directly from your code.</p> <p>This makes the work subtly complicated because the views must be created with the effect in mind and prepared for the switching operations. On the other side is geves you the most of the control so you are not constrained to a fading animation (as the example shows), but you can apply you fantasy to get the best. So first of all you have to create the storyboards in the xaml:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="fadeOut"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FadeOutThemeAnimation</span> <span style="color: #ff0000;">Duration</span><span style="color: #0000ff;">="00:00:01.00"</span> <span style="color: #ff0000;">Storyboard</span>.<span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="root"</span> <span style="color: #ff0000;">Completed</span><span style="color: #0000ff;">="fadeOut_Completed"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>In this example I'll show how to handle a fading animation from the MainPage to the secondary. The main page will be faded out and then replaced by the SecondaryPage. In the code behind you can handle this in different ways. In my case I simply drive the animation from the main page but, if you want also the secondary page to fade-in when entering, the best will be to make each page to drive his half of the animation. </p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> TaskCompletionSource<<span style="color: #0000ff;">bool</span>> tcs = <span style="color: #0000ff;">new</span> TaskCompletionSource<<span style="color: #0000ff;">bool</span>>();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> fadeOut_Completed(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> tcs.SetResult(<span style="color: #0000ff;">true</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">private</span> System.Threading.Tasks.Task FadeOut()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> fadeOut.Begin();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">return</span> tcs.Task;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> Button_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> var newView = await CreateNewView();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">bool</span> shown = await ApplicationViewSwitcher.PrepareForCustomAnimatedSwitchAsync(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> newView.Id, <span style="color: #0000ff;">this</span>.ApplicationView.Id, ApplicationViewSwitchingOptions.SkipAnimation);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;">if</span> (!shown)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> await <span style="color: #0000ff;">this</span>.FadeOut();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">int</span> fromId = <span style="color: #0000ff;">this</span>.ApplicationView.Id;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> await newView.ApplicationView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> async () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> await ApplicationViewSwitcher.SwitchAsync(newView.Id, fromId, ApplicationViewSwitchingOptions.SkipAnimation);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> }</pre> <!--CRLF--></div> </div> <p>The code here calls the PrepareForCustomAnimatedSwitchAsync method then starts the animation asynchronously. Once the animation completes, the task is closed (see the SetResult) and the control returns to the main thread. In this moment the interface has been faded out so, waitin the signal from the new view's dispatcher, its thread calls the SwitchAsync method that does the final part of the view switching.</p> <p>The operation is not so easy as expected but the effect may be beautiful to see. You can imagine to move object, apply a zoom, or simply use a fading animation as in my code. But the switching needs to be carefully planned and the framework does a little to help you.</p> <h4>Application switching and protocols</h4> <p>Once you understand the reason of creating multiple views, it become really useful to split parts of the logic to handle document specific tasks. In this context you may find useful to handle protocol or file association to directly open a secondary view. This is really easy to be implemented if you simply handle the protocol (or file) activation and you do the switch to the right view.</p> http://www.silverlightshow.net/items/Windows-8.1-Application-Views-improvements.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Application-Views-improvements.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Application-Views-improvements.aspx Tue, 26 Nov 2013 11:28:00 GMT Hello Windows 8.1: what's new in the update for developers Part 6: Updates in the tooling for Windows 8.1 <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-6-Updates-in-the-tooling-for-Windows-8.1.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/18B6XwV" data-text="Hello #Windows81: what's new in the update for devs #6: Updates in the tooling for #Win81. #win8dev" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-6-Updates-in-the-tooling-for-Windows-8.1.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-6-Updates-in-the-tooling-for-Windows-8.1.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/Win81_Part6.zip">Download the source code for this article</a></strong> </div> <p>Welcome to part 6, the last part in this article series on Windows 8.1. We’ve made it to the very end! In the previous parts, we’ve spent some time looking at the new things in Windows 8.1 itself. In this last part, we’re changing gears slightly and we will spend some time looking at the tool that makes it possible to create apps for Windows 8.1: Visual Studio 2013. There are a lot of interesting aspects coming with the new versions of the IDE so let’s see how we can become more productive as a XAML developer!</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Recording of Gill's webinar: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx">Andrea Boschin's Windows 8.1 article series</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <h2>Visual Studio 2013: the new standard</h2> <p>Visual Studio 2012 was a great tool but in some areas, it was still somewhat lacking. In the XAML editing experience we got, there were definitely some improvements possible. With Visual Studio 2013, Microsoft has done with Visual Studio for the XAML developer what it has done in the control area. A great number of improvements have been made. Let’s take a look at some of these.</p> <p>To start with, Visual Studio 2013 again comes in several SKUs: Professional, Premium and Ultimate. Somewhat surprising is that with 2013, you can only create and maintain Windows 8.1 applications. You cannot create new Windows 8 applications any longer, although you can maintain them. One could ask how long it will still be needed that we start the development of new Windows 8 apps and instead go to Windows 8.1 directly. That being said, you can do a side-by-side install of 2012 and 2013, should you still have the need to create new 8.0 apps. Of course, there’s also a free, Express edition, but we won’t spend any time on that here.</p> <p>A first question is: should I update my existing apps? Just so you’re clear on this: if you today have a Windows 8 app in the store, any user with Windows 8 or Windows 8.1 will be able to install that app. So from that point of view, there’s no need to immediately start panicking, thinking that you’re missing out on a lot of possible installs. If you want, you can in the store upload both a Windows 8 and a Windows 8.1 version of your app. Depending on the version of Windows used by the user, he’ll either get the 8.0 or the 8.1 version. But coming back to that question. There’s definitely a value in updating existing apps (and by updating I mean just opening the solution in 2013 and re-targeting, as shown a little further): your apps will start faster, certainly if they contain a ListView. The memory footprint of the app will also be lower. One of the main reasons for this is that Windows 8.1 doesn’t load in all keyed resources at startup, which has a huge performance impact! Also, panning on ListViews will definitely give a better experience (the fact that the ListView had issues redrawing items, has been fixed).</p> <p>So just by retargeting your app, you’ll get a lot of benefits. But how do you do this retargeting? Well, it’s pretty simple. Open your 2012/Windows 8 solution in your freshly installed VS2013. It will start by recommending that you should update, as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____________clip_image002_2.jpg"><img width="512" height="268" title="clip_image002" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image002" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____________clip_image002_thumb.jpg" /></a></p> <p>Hitting OK won’t do anything just yet. Head over to the Solution Explorer and right-click on the solution. Select Retarget to Windows 8.1 and sit back. Your app is now being readied to become a Windows 8.1 app!</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_______clip_image003_2.png"><img width="405" height="194" title="clip_image003" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image003" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_______clip_image003_thumb.png" /></a></p> <p>VS2013 brings a lot of goodness to the table. We’re getting a new project template, based on the Hub Control. This gives you a head start building an app that is built around the Hub Control.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_________clip_image004_2.png"><img width="509" height="179" title="clip_image004" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image004" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_________clip_image004_thumb.png" /></a></p> <p>Other improvements focus on better diagnostics, better integration for Azure Mobile Services (you can now add such a service through the Service Manager), shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/______clip_image006_2.jpg"><img width="644" height="449" title="clip_image006" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image006" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/______clip_image006_thumb.jpg" /></a></p> <h2>XAML Editing improvements</h2> <p>As mentioned, in the XAML editing experience, we could definitely use some improvements. Below is an overview of the things I think you’ll really want to know when you start on a new Windows 8.1 project using XAML!</p> <h3>Improved XAML IntelliSense</h3> <p>I was always sad (or should I say slightly frustrated…) when I accidentally typed StakPanel (forgetting the C for example). What happened was that Visual Studio automatically jumped to the first item in the IntelliSense list. Not what I wanted it to do.</p> <p>In VS2013, Microsoft has added some fuzzy logic that makes VS think about what you want IntellSense to do. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image007_2.png"><img width="445" height="318" title="clip_image007" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image007" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image007_thumb.png" /></a></p> <p>Also improved is the ability to work with closing tags. Normally, when we thought that a closing tag was no longer useful (so for example </TextBlock>) and we wanted to replace it with <TextBlock />, we had to do that manually.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image008_2.png"><img width="540" height="64" title="clip_image008" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image008" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image008_thumb.png" /></a></p> <p>VS2013 makes our lives again a bit easier: when I type a / in the opening tag, it will automatically remove the closing tag. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image009_2.png"><img width="558" height="59" title="clip_image009" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image009" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image009_thumb.png" /></a></p> <p>Another XAML editing improvement is tag matching. Assume you have a Grid and you want to replace it with a StackPanel. Normally, you start by changing the opening tag, then get a lot of VS squiggly lines, then change the closing tag. In VS2013, Microsoft has changed the experience there as well. When we start editing an opening tag, it will automatically match the closing tag as well.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image010_2.png"><img width="585" height="275" title="clip_image010" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image010" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image010_thumb.png" /></a></p> <p>There are some other tweaks in there such as matching the member you’re looking for, based on a substring (so finding StackPanel when you type Panel). Quite related is the ability to type SP when you want to add a StackPanel. Basically, what you’re doing then is using camel case matching.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image012_2.jpg"><img width="664" height="226" title="clip_image012" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image012" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image012_thumb.jpg" /></a></p> <h3>Data binding improvements</h3> <p>Also on the data binding front, Microsoft has added a lot of extra XAML features. If we specify the data source for the data binding in the XAML code itself, we’ll get more intelligent IntelliSense suggestions. Let’s take a look.</p> <p>Assume we have a basic viewmodel defined, named MainViewModel.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">public</span> <span class="kwrd">class</span> MainViewModel</pre> <pre><span class="lnum"> 2: </span>{</pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd">public</span> <span class="kwrd">string</span> FirstName { get; set; }</pre> <pre><span class="lnum"> 4: </span> <span class="kwrd">public</span> <span class="kwrd">string</span> LastName { get; set; }</pre> <pre class="alt"><span class="lnum"> 5: </span> </pre> <pre><span class="lnum"> 6: </span> <span class="kwrd">public</span> MainViewModel()</pre> <pre class="alt"><span class="lnum"> 7: </span> {</pre> <pre><span class="lnum"> 8: </span> <span class="kwrd">this</span>.FirstName = <span class="str">"Gill"</span>;</pre> <pre class="alt"><span class="lnum"> 9: </span> <span class="kwrd">this</span>.LastName = <span class="str">"Cleeren"</span>;</pre> <pre><span class="lnum"> 10: </span> }</pre> <pre class="alt"><span class="lnum"> 11: </span>}</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>We then instantiate this class as resource (for example at the app level):</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">Application</span></pre> <pre><span class="lnum"> 2: </span> <span class="attr">x:Class</span><span class="kwrd">="DataBindingInXaml.App"</span></pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="attr">xmlns</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre> <pre><span class="lnum"> 4: </span> <span class="attr">xmlns:x</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre> <pre class="alt"><span class="lnum"> 5: </span> <span class="attr">xmlns:local</span><span class="kwrd">="using:DataBindingInXaml"</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 6: </span> <span class="kwrd"><</span><span class="html">Application.Resources</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 7: </span> <span class="kwrd"><</span><span class="html">local:MainViewModel</span> <span class="attr">x:Key</span><span class="kwrd">="localMainViewModel"</span><span class="kwrd">></</span><span class="html">local:MainViewModel</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 8: </span> <span class="kwrd"></</span><span class="html">Application.Resources</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 9: </span><span class="kwrd"></</span><span class="html">Application</span><span class="kwrd">></span></pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>If we now set the DataContext for the entire page to this instance, we’ll get good IntelliSense on the properties in the viewmodel.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image014_2.jpg"><img width="504" height="200" title="clip_image014" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image014" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image014_thumb.jpg" /></a></p> <p>Note that this of course only works if the data context has been set via XAML. If you would use code-behind or perhaps a ViewModelLocator, this won’t work. You can still then use design-time data and you’ll get the same IntelliSense there as well.</p> <h3>Resources</h3> <p>It has also become easier to work with resources. If you have declared a resource anywhere in your project, you’ll get IntelliSense suggesting it to you. Below, you can see the instance of the viewmodel used above being suggested.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/__clip_image016_2.jpg"><img width="672" height="210" title="clip_image016" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image016" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/__clip_image016_thumb.jpg" /></a></p> <p>Notice that also the other resources (such as Brushes) are being suggested. VS2013 also gets the resources defined in the generic.xaml and adds them to the list. So although these resources have now been moved to a file outside of the scope of the project, we can still get the resources while editing the XAML code.</p> <h3>Go To Definition</h3> <p>With Visual Studio 2013, it has now become possible to do a Go To Defintion on a lot of things, including resources and data binding statements. </p> <p>Assume we have the following code (which is some default code that gets generated when executing the new Hub template):</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image018_2.jpg"><img width="763" height="86" title="clip_image018" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image018" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image018_thumb.jpg" /></a></p> <p>If we now press F12 (the default shortcut for navigating to the definition), VS2013 will search all possible resources and open the containing file if found. In this case, we’ll see the generic.xaml being opened. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image020_2.jpg"><img width="632" height="226" title="clip_image020" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image020" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image020_thumb.jpg" /></a></p> <p>This generic.xaml is the file that contains the default style definitions for controls. Previously, these were contained in the StandardStyles.xaml but that has changed with Windows 8.1. Now these styles have all been moved to the generic.xaml.</p> <p>But back to what we were looking at: we can see that we can navigate to resources. But F12 can do much more. Assume we have the same example again with the viewmodel. If we select the FirstName property and the F12 on that, we’ll be transferred to the property in the viewmodel automatically.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image021_2.png"><img width="640" height="102" title="clip_image021" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image021" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image021_thumb.png" /></a></p> <p>If you F12 on a built-in type, VS2013 will open the Object Browser. If we for example F12 with a StackPanel selected, we’ll see the following happening.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image023_2.jpg"><img width="662" height="451" title="clip_image023" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image023" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image023_thumb.jpg" /></a></p> <h2>Other XAML editing improvements</h2> <p>VS2013 also includes a number of handy editing improvements:</p> <ul> <li>Closing tag matching: if we change the opening tag (say we want to change a Grid into a StackPanel), we can simply change the opening tag and VS2013 will update the closing tag for us (VS2013 had this already for some time for HTML editing but now also has this for XAML). <br /> <a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image024_2.png"><img width="244" height="204" title="clip_image024" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image024" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image024_thumb.png" /></a></li> <li>XAML snippets: VS2013 now also supports snippets in XAML. We can manage snippets via the Snippet Manager (the default installation doesn’t contain any sadly). Tim Heuer has a good overview on how to create your own snippets here: <a href="http://timheuer.com/blog/archive/2013/07/08/xaml-code-snippets-for-visual-studio.aspx">http://timheuer.com/blog/archive/2013/07/08/xaml-code-snippets-for-visual-studio.aspx</a></li> <li>Improved commenting: if we want to comment out a large block of XAML and there are already XAML comments in there, the commenting feature used to fall over this. In VS2013, things have improved here as well, as VS2013 will notice that the block you want to comment out already contains XAML comments and make sure these get included in the comment as well.</li> </ul> <h2>Summary</h2> <p>In this article, we looked at the new features of Visual Studio 2013. With that, we have concluded this series on the new developer features of Windows 8.1. </p> <p>Stay tuned for more great content on Windows 8 here at SilverlightShow!</p> <h2>About the author</h2> <p>Gill Cleeren is Microsoft Regional Director, Silverlight MVP, Pluralsight trainer and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina. Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd, TechDays, DevDays, NDC Oslo, SQL Server Saturday Switzerland, Silverlight Roadshow in Sweden, Telerik RoadShow UK… Gill has written 2 books: “<a href="https://www.packtpub.com/microsoft-silverlight-4-data-and-services-cookbook/book">Silverlight 4 Data and Services Cookbook</a>” and <a href="http://www.packtpub.com/microsoft-silverlight-5-data-and-services-cookbook/book">Silverlight 5 Data and Services Cookbook</a> and is author of many articles for magazines and websites. You can find his blog at <a href="http://www.snowball.be/">www.snowball.be</a>. Twitter: @gillcleeren</p> http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-6-Updates-in-the-tooling-for-Windows-8.1.aspx editorial@silverlightshow.net (Gill Cleeren ) http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-6-Updates-in-the-tooling-for-Windows-8.1.aspx#comments http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-6-Updates-in-the-tooling-for-Windows-8.1.aspx Mon, 25 Nov 2013 18:28:00 GMT Hello Windows 8.1: what's new in the update for developers: Part 5: More improvements to the user experience <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-5-More-improvements-to-the-user-experience.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-5-More-improvements-to-the-user-experience.aspx" data-count="horizontal" data-text="Hello #Windows81: what's new in the update for devs #5: More improvements to the user experience. #win8dev" data-url="http://slshow.net/1b7oDmc">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-5-More-improvements-to-the-user-experience.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/Win81_Part5.zip">Download the source code for this article</a></strong> </div> <p>Hi and welcome to the fifth part of our exploration of developer updates in Windows 8. We’ve covered a lot of ground already, starting with our tour of XAML improvements (together with Andrea Boschin’s articles), going through some interesting improvements in WinRT and also taking a look at some important changes in the user experience. The latter was the topic of the 4<sup>th</sup> article in this series. In this part, we are going to continue by looking at some experience-related changes that we have in Windows 8.1.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Recording of Gill's webinar: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx">Andrea Boschin's Windows 8.1 article series</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p>We are going to start by looking at the new tile sizes and we’ll also briefly look at the new UX guidelines issued by Microsoft. Let’s get started straight away!</p> <h2>New Tiles sizes</h2> <p>In the entire Windows 8 experience, the Start screen is a central aspect. It allows us to pin tiles and this way, it offers the user a customizable way of changing how it behaves. On that Start screen, the tiles play a very important role. The tiles are the ways of interacting with the Start screen. We have already covered here at SilverlightShow the tiles for Windows 8 already quite a lot. Tiles are much more than a shortcut on your desktop. They allow the user customize the Start screen by pinning those tiles which are important for him and often, give a good ‘tile experience’. Since the tile is more than just a way to open an app, it’s important that the developer makes good use of the tile. By showing updates on the tile (local or via push notifications), the tile can lure the user back into the app by showing interesting content. This way, the tile can be considered an extension of the application.</p> <p>In Windows 8, we were limited to using 2 tile sizes. While those were OK, they didn’t allow fine-grained control over the Start screen, certainly if you compared to the experience we’re getting on Windows Phone. Below, you can see a screenshot of the default Windows 8 experience. Only 2 types of tiles are supported: the square and the wide tile. The square tile was 150x150 pixels, the wide tile was 310x150 pixels.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___________clip_image002_2.jpg"><img width="423" height="386" title="clip_image002" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image002" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___________clip_image002_thumb.jpg" /></a></p> <p>With Windows 8.1, Microsoft is introducing two more tile sizes, so we now have 4 in total. The extra’s we’re getting are the small (70x70 pixels) and the large tile (310x310 pixels). This gives the end-user more control on how he wants to organize his Start screen. Below is another screenshot, this time of Windows 8.1. This screen features all tile sizes.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image004_2.jpg"><img width="570" height="388" title="clip_image004" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image004" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image004_thumb.jpg" /></a></p> <p>Since now 3 out of 4 tile sizes are square, Microsoft has renamed the original square tile size to medium. So, to conclude, we now have small, medium, large and wide tiles available. This of course also has a consequence for the live tile templates, but more on that a little further.</p> <p>Some other things have changed with the new tiles as well. In Windows 8, we had to include a square tile but when we included a wide tile, the wide tile was pinned by default to the Start screen. In Windows 8.1, we can now specify that you want either the wide or the square tile to be used. You make this selection in the application manifest. Note you can’t set the small or the large as default pin size. Also note that Windows 8.1 doesn’t add the tile by default to the Start screen (which is a great improvement).</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image006_2.jpg"><img width="501" height="215" title="clip_image006" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image006" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image006_thumb.jpg" /></a></p> <p>In our assets, we must include as the bare minimum the square and the small tile. If you omit the small tile assets, your app will still build and run, since Windows will create the small tile from the assets of the square tile.</p> <p>A more important change is the name of the live tile templates. When we update a tile, we basically are sending a piece of XML (the tile template). Since the square tile is no longer named “square”, the templates have changed names as well. For example, the commonly used TileSquareImage is now renamed to TileSquare150x150Image (so including the size since we have 3 which are square). </p> <p>If you’re just updating the tiles from the application, you won’t have a lot of problems (you can use the updated version of the NotificationExtensions library) to work with these new tile template names. But if you’re working with a push notification that pushes both to Windows 8 and Windows 8.1 clients, you may need to change a few things. If you think about it, it’s quite logical: the new names are only known by 8.1. By default, Windows 8 would ignore the new names, thinking they aren’t valid. In this case, what you need to do is including a fallback mechanism. What you need to do, is including a version=2 and a fallback name. The latter indicates the old name the template was known by, therefore letting Windows 8 understand the template as well. If you’re sending a tile update with a large tile update, that won’t do a lot since Windows 8 didn’t have those tiles yet.</p> <p>Let’s take a look at a sample. We are going to use the NotificationsExtensions library in order not having to write the XML but using the object model around the templates. Below is a screenshot of the generated XML in the application.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image008_2.jpg"><img width="509" height="339" title="clip_image008" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image008" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image008_thumb.jpg" /></a></p> <p>Assume that for this application, the developer wants to give the user the choice to either create a medium (square150x150), wide (310x150) and a large (310x310) tile update. If we want to make sure that just any of these 3 templates will receive the update, we need to include them all in the tile update (if we omit one or more, only when the user has the application pinned in the same tile size, the tile will update). Also note that if the user has the application pinned in the small tile size, no live tile update will be received (small tiles don’t support live tile updates, they only support badge updates). That’s why we never have to include that template.</p> <p>In the sample, we have created a reference to the NotificationsExtensions library.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image009_2.png"><img width="339" height="398" title="clip_image009" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image009" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image009_thumb.png" /></a></p> <p>Once we have this reference in place, we can start using the object model around the tiles. In the code below, we are going to create an update for the large tile using the ITileSquare310x310Text05 template. We also want the update to appear if the user has the app pinned using a wide tile; in this case, we’ll use the ITileWide310x150Text03 template. And to be complete, we also need to specify what we want to show if the app is pinned with the square tile: we use the ITileSquare150x150Text04 for this.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">string</span> userMessage = TileTextTextBox.Text;</pre> <pre><span class="lnum"> 2: </span>ITileSquare310x310Text05 tileContent = </pre> <pre class="alt"><span class="lnum"> 3: </span> TileContentFactory.CreateTileSquare310x310Text05();</pre> <pre><span class="lnum"> 4: </span>tileContent.TextHeading.Text = userMessage;</pre> <pre class="alt"><span class="lnum"> 5: </span> </pre> <pre><span class="lnum"> 6: </span>ITileWide310x150Text03 wide310x150Content = </pre> <pre class="alt"><span class="lnum"> 7: </span> TileContentFactory.CreateTileWide310x150Text03();</pre> <pre><span class="lnum"> 8: </span>wide310x150Content.TextHeadingWrap.Text = userMessage;</pre> <pre class="alt"><span class="lnum"> 9: </span> </pre> <pre><span class="lnum"> 10: </span>ITileSquare150x150Text04 square150x150Content = </pre> <pre class="alt"><span class="lnum"> 11: </span> TileContentFactory.CreateTileSquare150x150Text04();</pre> <pre><span class="lnum"> 12: </span>square150x150Content.TextBodyWrap.Text = userMessage;</pre> <pre class="alt"><span class="lnum"> 13: </span>wide310x150Content.Square150x150Content = square150x150Content;</pre> <pre><span class="lnum"> 14: </span> </pre> <pre class="alt"><span class="lnum"> 15: </span>tileContent.Wide310x150Content = wide310x150Content;</pre> <pre><span class="lnum"> 16: </span> </pre> <pre class="alt"><span class="lnum"> 17: </span>TileUpdateManager.CreateTileUpdaterForApplication().</pre> <pre><span class="lnum"> 18: </span> Update(tileContent.CreateNotification());</pre> <pre class="alt"><span class="lnum"> 19: </span> </pre> <pre><span class="lnum"> 20: </span>ResultTextBox.Text = tileContent.GetContent();</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>Note that we’re basically chaining the tile updates. This results in the following XML to be sent to the tile:</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">tile</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 2: </span> <span class="kwrd"><</span><span class="html">visual</span> <span class="attr">version</span><span class="kwrd">='2'</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd"><</span><span class="html">binding</span> <span class="attr">template</span><span class="kwrd">='TileSquare150x150Text04'</span> <span class="attr">fallback</span><span class="kwrd">='TileSquareText04'</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 4: </span> <span class="kwrd"><</span><span class="html">text</span> <span class="attr">id</span><span class="kwrd">='1'</span><span class="kwrd">></span>New article on SilverlightShow!<span class="kwrd"></</span><span class="html">text</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 5: </span> <span class="kwrd"></</span><span class="html">binding</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 6: </span> <span class="kwrd"><</span><span class="html">binding</span> <span class="attr">template</span><span class="kwrd">='TileWide310x150Text03'</span> <span class="attr">fallback</span><span class="kwrd">='TileWideText03'</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 7: </span> <span class="kwrd"><</span><span class="html">text</span> <span class="attr">id</span><span class="kwrd">='1'</span><span class="kwrd">></span>New article on SilverlightShow!<span class="kwrd"></</span><span class="html">text</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 8: </span> <span class="kwrd"></</span><span class="html">binding</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 9: </span> <span class="kwrd"><</span><span class="html">binding</span> <span class="attr">template</span><span class="kwrd">='TileSquare310x310Text05'</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 10: </span> <span class="kwrd"><</span><span class="html">text</span> <span class="attr">id</span><span class="kwrd">='1'</span><span class="kwrd">></span>New article on SilverlightShow!<span class="kwrd"></</span><span class="html">text</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 11: </span> <span class="kwrd"></</span><span class="html">binding</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 12: </span> <span class="kwrd"></</span><span class="html">visual</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 13: </span><span class="kwrd"></</span><span class="html">tile</span><span class="kwrd">></span></pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>Note the fallback attribute on each of the binding elements: this way, a Windows 8 installation that would receive this same XML would still be able to update its tile. Also note that the version is now 2. </p> <p>If you want a visual example of all tile templates that are now available in Windows 8.1, take a look at <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx">http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx</a>.</p> <h2>More chrome</h2> <p>To finish this article, let’s take a look at the general UX guidelines. I’m not going to take you through all of these guidelines, they can be found at <a href="http://msdn.microsoft.com/en-US/library/windows/apps/hh779072">http://msdn.microsoft.com/en-US/library/windows/apps/hh779072</a>. </p> <p>However, I do want to put some emphasis on some striking changes that we see in the built-in applications such as the Music or the Health and Fitness app. One of the biggest design principles in Windows 8 was the Content Before Chrome principle. While this still stands in Windows 8, there are some remarkable changes here. Below you can see a screenshot of the XBOX Music app. What we see on the left here, is pure navigation. Those are tabs and in fact, the entire application is now basically a tabbed interface. Also, not that right below the Collection title, we have a couple of buttons, which also do some form of navigation.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image011_2.jpg"><img width="461" height="259" title="clip_image011" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image011" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image011_thumb.jpg" /></a></p> <p>In the Health and Fitness application, we see the same trend.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image013_2.jpg"><img width="462" height="258" title="clip_image013" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image013" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image013_thumb.jpg" /></a></p> <p>In the screenshot above, all those buttons basically do nothing but navigation. They are content, so they adhere to the principle but it’s interesting to see that those are controls, directly in the app’s UI that perform some action. Previously, Microsoft would have recommended to hide those, perhaps in the app bar. Now, they are visible directly from the application.</p> <p>Is this a good thing? Definitely! Microsoft lets the design guidelines for Windows 8 evolve, based on feedback. With Windows 8.1, we’re getting more options this way to create more compelling user interfaces, which can only be a benefit for the end user!</p> <h2>Summary</h2> <p>In this article, we’ve looked at some more user experience changes coming with Windows 8.1. Stay tuned for the last article on the tooling using Visual Studio and Blend!</p> <h2>About the author</h2> <p>Gill Cleeren is Microsoft Regional Director, Silverlight MVP, Pluralsight trainer and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina. Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd, TechDays, DevDays, NDC Oslo, SQL Server Saturday Switzerland, Silverlight Roadshow in Sweden, Telerik RoadShow UK… Gill has written 2 books: “<a href="https://www.packtpub.com/microsoft-silverlight-4-data-and-services-cookbook/book">Silverlight 4 Data and Services Cookbook</a>” and <a href="http://www.packtpub.com/microsoft-silverlight-5-data-and-services-cookbook/book">Silverlight 5 Data and Services Cookbook</a> and is author of many articles for magazines and websites. You can find his blog at <a href="http://www.snowball.be/">www.snowball.be</a>. Twitter: @gillcleeren</p> http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-5-More-improvements-to-the-user-experience.aspx editorial@silverlightshow.net (Gill Cleeren ) http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-5-More-improvements-to-the-user-experience.aspx#comments http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-5-More-improvements-to-the-user-experience.aspx Wed, 20 Nov 2013 11:21:00 GMT Hello Windows 8.1: what's new in the update for developers: Part 4: The new user experience <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-4-The-new-user-experience.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/1gXFHx4" data-text="Hello #Windows81: what's new in the update for devs: Part 4: The new user experience. #win8dev" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-4-The-new-user-experience.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-4-The-new-user-experience.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/hello_win81_Part4.zip">Download the source code for this article</a></strong> </div> <p>Hi and welcome to the fourth part in this series on new features in Windows 8.1. So far, we’ve covered the new OS from the user’s point of view, some of the new XAML features, some interesting WinRT classes. In this part, we’ll cover some novelties in the user experience like the new screen sizes and the new options for working with tiles.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Recording of Gill's webinar: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx">Andrea Boschin's Windows 8.1 article series</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <h2>New Window sizes</h2> <p>In Windows 8, apps could basically run in 3 modes. By default, an application was running full-screen. However, Windows 8 wasn’t limited to running just one app at any given point like for example iOS. With SnapView, an app could run in a so-called “snap view”, basically a narrow view of 320 px (x the scale factor if any) that is either docked on the left or the right of the screen. The second app running at this point was then in filled mode. So in total, apps could either be in full, filled or snapped mode. When publishing an app to the store, one of the requirements was making sure that your app would run perfectly in these 3 modes. It wasn’t allowed to omit adding the snap view: if running in snapped mode didn’t make sense for your scenario, you still had to include it and perhaps show an image or some text asking the user to run the app in full-screen mode.</p> <p>While this was OK, it was still somewhat limiting. That’s probably what Microsoft also thought and so with Windows 8.1, they’ve completely changed the way this works. We now basically can run more apps and they can run in all kinds of screen sizes. Also, the snap mode concept has now become optional, but more on that later. </p> <p>As you can see from the screenshot below, we can run 3 apps on one screen, where one of the 3 is running in snapped mode. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/__________clip_image002_2.jpg"><img width="456" height="258" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/__________clip_image002_thumb.jpg" alt="clip_image002" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image002" /></a></p> <p>Or we can run 10 apps, spread over 3 screens. I’m not sure this is a very useful setup but it proves the point that we can run up to 4 apps on one screen. The number of apps you can run on your screen depends on the screen resolution and the physical size of the monitor.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/________clip_image004_2.png"><img width="458" height="231" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/________clip_image004_thumb.png" alt="clip_image004" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image004" /></a></p> <p>The requirements that you need to follow when building an app have thus also changed. Your app needs to offer the full experience, anywhere from 500px upwards. That means that your app can focus on that 500px being the minimum resolution but it has to make sure that the user can get the full experience at this resolution. The latter is important and is also a change with what we had with snap view. In snapped mode, the app had to give the user a vertical scroll experience, since the 320px-wide window was too narrow to do horizontal scrolling. Now, we can use a horizontal scrolling experience without problems: 500px is wide enough for this, the user won’t accidentally drag the resize-gutter.</p> <p>So how does this translate into your app then? Well, that depends a bit on the scenario. If you have a “regular” horizontal scrolling app, you probably don’t have to do anything special. Just test that your app looks good at a width of 500px should be enough. In the screenshot below, you can see the Bing Travel app, which is running in the new minimum width of 500px. It simply offers the same experience as in full screen.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image006_2.jpg"><img width="454" height="250" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image006_thumb.jpg" alt="clip_image006" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image006" /></a></p> <p>If the app is a multi-column app, one option you have is hiding columns when you have less available space. The Mail app does this, as you can see on the screenshot below. Notice the arrow at the top, which will unhide other colums.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/__clip_image008_2.png"><img width="450" height="255" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/__clip_image008_thumb.png" alt="clip_image008" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image008" /></a></p> <p>If your app is a fixed-size app, you can make it smaller, keeping the aspect ratio in place, as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image012_2.png"><img width="450" height="268" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image012_thumb.png" alt="clip_image012" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image012" /></a></p> <p>Let’s now take a look at how all this works from Visual Studio. For this demo, I’m going to start by using Visual Studio 2012 (the “old” version!) and simply create a new Grid-based application. This template includes a SnapView mode by default.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image014_2.jpg"><img width="454" height="315" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image014_thumb.jpg" alt="clip_image014" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image014" /></a></p> <p>When we simply build and run this app on Windows 8.1 (which doesn’t have snap mode built-in by default), the application will run in some kind of compatibility mode, known as pillarboxing. Note in the screenshot below that the snap view still works. Any resolution between 320px and 500px is however now supported, but the snap view sits in the middle of 2 black pillars, hence the name pillarboxing.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image016_2.jpg"><img width="456" height="253" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image016_thumb.jpg" alt="clip_image016" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image016" /></a></p> <p>When we now open this same project in Visual Studio 2013, we can retarget the app to become a Windows 8.1 app. Simply open the solution and from the Solution Explorer, select Retarget to Windows 8.1.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image018_2.jpg"><img width="450" height="249" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image018_thumb.jpg" alt="clip_image018" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image018" /></a></p> <p>When we now run the app again (as a Windows 8.1 app), the app doesn’t support snap view anymore: the narrowest we can make it is now 500px, as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image020_2.jpg"><img width="443" height="247" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image020_thumb.jpg" alt="clip_image020" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image020" /></a></p> <p>If we have a valid reason to continue supporting snap view even in Windows 8.1, we still can. However, we need to do this explicitly. Several scenarios come to mind where this is indeed still useful, including a monitoring app, a Twitter app or a video player app that wants to allow the user to use a smaller window to continue watching video.</p> <p>To do so, go to the application manifest and in there, set the value for minimum width from there.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image021_2.png"><img width="441" height="151" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image021_thumb.png" alt="clip_image021" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image021" /></a></p> <p>If we now select 320px and then run the app again, we get the following result. As you can see, the app now supports any width from 320px upwards. Between 320px and 500px, we see the snap view but this isn’t running in the pillarboxing mode any longer: the snap view window now gets all the available space on the screen. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image023_2.jpg"><img width="431" height="235" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image023_thumb.jpg" alt="clip_image023" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image023" /></a></p> <p>Some of the code related to managing the views, is deprecated. Assume in your Windows 8 code, you’ll have code that checks which is the current application state (FullScreen, Snapped, Filled) so that based on this value, you can use the VisualStateManager to go to a particular state. If we run this code in Visual Studio 2013, we can see that this code is now deprecated, as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image025_2.jpg"><img width="441" height="141" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image025_thumb.jpg" alt="clip_image025" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image025" /></a></p> <p>So instead of checking in which state we are, we’ll need to work with numeric values that indicate the current width of the screen. Some code for this is shown next. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image027_2.jpg"><img width="438" height="98" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image027_thumb.jpg" alt="clip_image027" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image027" /></a></p> <p>Also, the commonly used TryUnsnap() method is deprecated in Windows 8.1, quite logical since snapping isn’t supported as a default feature anymore.</p> <h2>The new Search experience</h2> <p>Another area where some the user experience has changed quite a lot in Windows 8.1, is Search. Previously, searching in an app had to be done by using the Search contract. The Search contract was accessible through the Search charm in the Charms bar. With the Search contract, it was also possible to search within apps: apps could register for the contract and in turn, Windows placed the apps in a list that users could select as the target for their searches.</p> <p>One problem that arose with this approach to searching is that many people had problems locating the Search option within an app (and perhaps left the app, frustrated they couldn’t search it…). In Windows 8.1, Microsoft has changed Search by making it available through a control instead: the SearchBox control. The control lives in the Windows.UI.Xaml.Controls namespace, just like many other controls. In the screenshow below, you can see the control in action.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image029_2.jpg"><img width="204" height="244" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image029_thumb.jpg" alt="clip_image029" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px;" title="clip_image029" /></a></p> <p>As you can probably get from the screenshot, the user experience we’re getting from the control is pretty similar to what we had before in the Search pane, but now integrated in the app’s UI. And that would be a correct assumption: the control offers search suggestions and search recommendations in much the same way as before. </p> <p>Code-wise, things haven’t changed a lot either: the control supports the same events and search mechanisms as well. Let’s take a look at some sample code.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image031_2.jpg"><img width="244" height="191" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image031_thumb.jpg" alt="clip_image031" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" title="clip_image031" /></a></p> <p>The control can be added just like any other control in XAML.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">SearchBox</span> <span class="attr">Name</span><span class="kwrd">="MainSearchBox"</span> <span class="attr">QuerySubmitted</span><span class="kwrd">="MainSearchBox_QuerySubmitted"</span> </pre> <pre><span class="lnum"> 2: </span> <span class="attr">SuggestionsRequested</span><span class="kwrd">="MainSearchBox_SuggestionsRequested"</span> <span class="attr">Width</span><span class="kwrd">="200"</span> </pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="attr">HorizontalAlignment</span><span class="kwrd">="Center"</span><span class="kwrd">></</span><span class="html">SearchBox</span><span class="kwrd">></span></pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>In code, we can now handle what needs to happen when the user types (give suggestions) and when he hits Enter (query is being submitted). In the code below, we can see that the entered query arrives in code via the SearchBoxQuerySubmittedEventArgs.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">private</span> <span class="kwrd">void</span> MainSearchBox_QuerySubmitted(SearchBox sender, </pre> <pre><span class="lnum"> 2: </span> SearchBoxQuerySubmittedEventArgs args)</pre> <pre class="alt"><span class="lnum"> 3: </span>{</pre> <pre><span class="lnum"> 4: </span> QueryTextBlock.Text = <span class="str">"You searched for "</span> + args.QueryText; </pre> <pre class="alt"><span class="lnum"> 5: </span>}</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>When we start typing, we want to show a list of suggestions. In the event handler, we’re getting in an instance of SearchBoxSuggeestionsRequestedEventArgs. This contains the current value in the SearchBox (QueryText) as well as the SearchSuggestionCollection (through the Request property). Using these two, we can get a list of suggestions and add these to the SearchSuggestionCollection. Note that the limitation of 5 items we had in Windows 8 is gone in Windows 8.1 for the SearchBox control.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">private</span> <span class="kwrd">void</span> MainSearchBox_SuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)</pre> <pre><span class="lnum"> 2: </span>{</pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd">string</span> queryText = args.QueryText;</pre> <pre><span class="lnum"> 4: </span> SearchSuggestionCollection suggestionCollection = args.Request.SearchSuggestionCollection;</pre> <pre class="alt"><span class="lnum"> 5: </span> <span class="kwrd">foreach</span> (<span class="kwrd">string</span> suggestion <span class="kwrd">in</span> cities)</pre> <pre><span class="lnum"> 6: </span> {</pre> <pre class="alt"><span class="lnum"> 7: </span> <span class="kwrd">if</span> (suggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))</pre> <pre><span class="lnum"> 8: </span> {</pre> <pre class="alt"><span class="lnum"> 9: </span> suggestionCollection.AppendQuerySuggestion(suggestion);</pre> <pre><span class="lnum"> 10: </span> }</pre> <pre class="alt"><span class="lnum"> 11: </span> }</pre> <pre><span class="lnum"> 12: </span>}</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>If you’ve developed before against the Search contract, you’ll see that the code is pretty similar. In fact, when you have to make changes, they’ll be limited mostly to making your code point to the control instead of the SearchPane, the rest is very similar.</p> <p>If you have an app that works with the Search contract today, what will happen? Well, remember that in the beginning of this article series, we talked about ‘Almost non-breaking’? This is one area where things will break in terms of UX. While the code will continue to work, the user won’t be getting a great experience anymore with your app. This therefore definitely requires an update of your existing app! </p> <h2>Summary</h2> <p>In this part, we looked at 2 major changes in the UX, namely the window sizes and the Search option. Stay tuned for more Windows 8.1 changes.</p> <h2>About the author</h2> <p>Gill Cleeren is Microsoft Regional Director, Silverlight MVP, Pluralsight trainer and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina. Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd, TechDays, DevDays, NDC Oslo, SQL Server Saturday Switzerland, Silverlight Roadshow in Sweden, Telerik RoadShow UK… Gill has written 2 books: “<a href="https://www.packtpub.com/microsoft-silverlight-4-data-and-services-cookbook/book">Silverlight 4 Data and Services Cookbook</a>” and <a href="http://www.packtpub.com/microsoft-silverlight-5-data-and-services-cookbook/book">Silverlight 5 Data and Services Cookbook</a> and is author of many articles for magazines and websites. You can find his blog at <a href="http://www.snowball.be/">www.snowball.be</a>. Twitter: @gillcleeren</p> http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-4-The-new-user-experience.aspx editorial@silverlightshow.net (Gill Cleeren ) http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-4-The-new-user-experience.aspx#comments http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-4-The-new-user-experience.aspx Mon, 18 Nov 2013 12:15:00 GMT Hello Windows 8.1: what's new in the update for developers: Part 3: More WinRT improvements <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-3-More-WinRT-improvements.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-3-More-WinRT-improvements.aspx" data-count="horizontal" data-text="Hello #Windows81: what's new in the update for devs: Part 3: More #WinRT improvements. #win8dev" data-url="http://slshow.net/1e2Zt6W">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-3-More-WinRT-improvements.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/hello_win81_Part3.zip">Download the source code for this article</a></strong> </div> <p>Hello and welcome to part 3 of our exploration of new developer features in Windows 8.1! In this third part, we will continue looking at some new additions and changes to the WinRT library, the base class library for Windows 8 development. Just to recap, we already covered some XAML stuff and the RenderTargetBitmap class in the previous article. There are some really interesting classes in WinRT that enable new app scenarios and that’s the focus of this article. Among others, we will cover speech synthesis, the new HTTP API and the Contact Manager API.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Recording of Gill's webinar: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx">Andrea Boschin's Windows 8.1 article series</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <h2>The new HTTP API</h2> <p>For their data needs, Windows 8 applications are required to work with services. Apart from a SQLite implementation, Windows 8 apps have no local DB access (unless we build one on top of XML files). For up-to-date date however, we have to resort to using services. Windows 8 has quite a few options in this area, including WCF, REST, RSS and much more.</p> <p>REST (XML or JSON based) services are very popular nowadays. Many web APIs are using it to expose their functionality. In Windows 8, we had the System.Net namespace which contained the HttpClient class (which replaced the WebClient class we had previously in Windows 8). With Windows 8.1, we are getting a new version of the HttpClient, which now lives entirely in WinRT, the Windows.Web.Http.HttpClient (and related classes in Windows.Web.Http). In terms of functionality, the API is more powerful than the one it is replacing; in terms of API, it’s still pretty similar to the old one. Some of the extra functions that are supported in this new version are caching support, access to cookies from the code (wasn’t possible with the old API) and filters. </p> <p>In the first demo, we’ll use the HttpClient and ask it to load a file from the cache if available. Initially, we’re making the call to the network resource, as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____image_2.png"><img width="418" height="185" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____image_thumb.png" alt="image" style="border-width: 0px; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-style: solid;" title="image" /></a></p> <p>After this call, the page is cached by the system. Subsequent calls can now be served from cache.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____image_4.png"><img width="415" height="143" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____image_thumb_1.png" alt="image" style="border-width: 0px; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-style: solid;" title="image" /></a></p> <p>Let’s see how we’ve made these call using code. We’re using an HttpClient and the HttpBaseProtocolFilter. The latter is used to configure how the call is made using the HttpClient instance so it’s this filter that we use to specify we want to use the default cache behaviour. On the new HttpClient, we can use the same methods to get a network resource, in this case, the GetAsyns. After we’ve received the response in the form of an HttpResponseMessage (again the same class as with the “old” HttpClient), we can use the Source property to figure out if we got the cached version of a new instance.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">private</span> HttpBaseProtocolFilter filter;</pre> <pre><span class="lnum"> 2: </span><span class="kwrd">private</span> HttpClient httpClient;</pre> <pre class="alt"><span class="lnum"> 3: </span> </pre> <pre><span class="lnum"> 4: </span><span class="kwrd">public</span> MainPage()</pre> <pre class="alt"><span class="lnum"> 5: </span>{</pre> <pre><span class="lnum"> 6: </span> <span class="kwrd">this</span>.InitializeComponent();</pre> <pre class="alt"><span class="lnum"> 7: </span> </pre> <pre><span class="lnum"> 8: </span> filter = <span class="kwrd">new</span> HttpBaseProtocolFilter();</pre> <pre class="alt"><span class="lnum"> 9: </span> httpClient = <span class="kwrd">new</span> HttpClient(filter);</pre> <pre><span class="lnum"> 10: </span> <span class="rem">//Let's use default cache behavior --> always used cached version</span></pre> <pre class="alt"><span class="lnum"> 11: </span> filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.Default;</pre> <pre><span class="lnum"> 12: </span> </pre> <pre class="alt"><span class="lnum"> 13: </span>}</pre> <pre><span class="lnum"> 14: </span>…</pre> <pre class="alt"><span class="lnum"> 15: </span>HttpResponseMessage response = await httpClient.GetAsync(<span class="kwrd">new</span> Uri(AddressTextBox.Text));</pre> <pre><span class="lnum"> 16: </span><span class="kwrd">string</span> result = <span class="kwrd">string</span>.Empty;</pre> <pre class="alt"><span class="lnum"> 17: </span>result = response.Source + Environment.NewLine;</pre> <pre><span class="lnum"> 18: </span>result += SerializeHeaders(response);</pre> <pre class="alt"><span class="lnum"> 19: </span> </pre> <pre><span class="lnum"> 20: </span>ResultTextBox.Text = result;</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>If we now want to get access to the cookies that were sent to the device when making the request, we can again use the HttpClient class which now gives access to this collection. In the screenshot below, we can see the cookies being read.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___image_6.png"><img width="401" height="274" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___image_thumb_2.png" alt="image" style="border-width: 0px; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-style: solid;" title="image" /></a></p> <p>Getting access to the cookies is done using the following lines of code. On the filter, we use the HttpCookieManager, which returns us a collection of cookies associated with the request.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>HttpBaseProtocolFilter filter = <span class="kwrd">new</span> HttpBaseProtocolFilter();</pre> <pre><span class="lnum"> 2: </span>HttpCookieCollection cookieCollection = </pre> <pre class="alt"><span class="lnum"> 3: </span> filter.CookieManager.GetCookies(<span class="kwrd">new</span> Uri(AddressTextBox.Text));</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>The HttpClient has more options, including for example the RetryFilter. This is handy if the server replies with a 503 including a Retry-After header, which will then indicate to the HttpClient that the request is to be retried after the indicated amount of time. As you can understand, this new API gives us many more options built-in, allowing us to focus on the business-side of things, instead of the technical stuff surrounding the actual creation of the requests.</p> <h2>Speech Synthesis from a WinRT app</h2> <p>Another interesting new feature in Windows 8.1 is speech synthesis. As the name implies, this enables a Windows 8.1 application to read out text to the user. While this may not seem like a big deal, there are a number of interesting scenarios possible with this:</p> <ul> <li>Turn-by-turn navigation applications can now use the built-in speech synthesis capabilities to read out instructions </li> <li>An ebook application can read out the book contents instead of the user having to read the book </li> <li>Prompt the user for input </li> </ul> <p>Another interesting aspect is accessibility of your application. If you want to build an app that makes it easy for people with accessibility issues to work with your app and have it read out the names of the input fields for the user. This is certainly an interesting aspect since in some countries, government-owned software and sites need to be conform certain rules regarding accessibility.</p> <p>The entire concept works based on the classes available in the Windows.Media.SpeechSynthesis namespace. Basically, what happens is that we can build up a stream by reading out text and that stream will then be the source for a MediaElement that will then read out the contents of the stream. Let’s take a look.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/__image_8.png"><img width="386" height="157" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/__image_thumb_3.png" alt="image" style="border-width: 0px; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-style: solid;" title="image" /></a></p> <p>Windows 8 comes with a number of built-in voices, based on the installed languages. On my device, there are 3 voices installed (because of my langauge settings).</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/__image_10.png"><img width="385" height="196" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/__image_thumb_4.png" alt="image" style="border-width: 0px; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-style: solid;" title="image" /></a></p> <p>The 2 main classes that enable this are the SpeechSynthesizer and the SpeechSynthesisStream. We have to use the SpeechSynthesizer, assign it a voice to use and pass it the text it needs to read out. That returns a SpeechSynthesisStream which in turn can be set as the source for the MediaElement that needs to read out the contents.</p> <p>In the code below, we do the first part: we assign the voice to use and also fill the ComboBox with all available voices.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>speechSynthesizer = <span class="kwrd">new</span> SpeechSynthesizer();</pre> <pre><span class="lnum"> 2: </span><span class="kwrd">this</span>.InitializeComponent();</pre> <pre class="alt"><span class="lnum"> 3: </span> </pre> <pre><span class="lnum"> 4: </span>var allVoices = Windows.Media.SpeechSynthesis.SpeechSynthesizer.AllVoices;</pre> <pre class="alt"><span class="lnum"> 5: </span> </pre> <pre><span class="lnum"> 6: </span>VoiceInformation currentVoice = <span class="kwrd">this</span>.speechSynthesizer.Voice;</pre> <pre class="alt"><span class="lnum"> 7: </span> </pre> <pre><span class="lnum"> 8: </span><span class="kwrd">foreach</span> (VoiceInformation voice <span class="kwrd">in</span> allVoices)</pre> <pre class="alt"><span class="lnum"> 9: </span>{</pre> <pre><span class="lnum"> 10: </span> ComboBoxItem item = <span class="kwrd">new</span> ComboBoxItem();</pre> <pre class="alt"><span class="lnum"> 11: </span> item.Name = voice.DisplayName;</pre> <pre><span class="lnum"> 12: </span> item.Tag = voice;</pre> <pre class="alt"><span class="lnum"> 13: </span> item.Content = voice.DisplayName;</pre> <pre><span class="lnum"> 14: </span> <span class="kwrd">this</span>.VoiceComboBox.Items.Add(item);</pre> <pre class="alt"><span class="lnum"> 15: </span> </pre> <pre><span class="lnum"> 16: </span> <span class="kwrd">if</span> (currentVoice.Id == voice.Id)</pre> <pre class="alt"><span class="lnum"> 17: </span> {</pre> <pre><span class="lnum"> 18: </span> item.IsSelected = <span class="kwrd">true</span>;</pre> <pre class="alt"><span class="lnum"> 19: </span> <span class="kwrd">this</span>.VoiceComboBox.SelectedItem = item;</pre> <pre><span class="lnum"> 20: </span> }</pre> <pre class="alt"><span class="lnum"> 21: </span>}</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>When we now click on the Button, we need to indicate the text we want to read out. Since this is a call that can take some time, it’s an async process. This returns a SynthesisStream instance. If the latter isn’t null, we use this stream as the source for the MediaElement. This MediaElement has its AutoPlay property set to true so it will start playing automatically.</p> <h4></h4> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">try</span></pre> <pre><span class="lnum"> 2: </span>{</pre> <pre class="alt"><span class="lnum"> 3: </span> synthesisStream = await <span class="kwrd">this</span>.speechSynthesizer.SynthesizeTextToStreamAsync(MainTextBox.Text);</pre> <pre><span class="lnum"> 4: </span>}</pre> <pre class="alt"><span class="lnum"> 5: </span><span class="kwrd">catch</span> (Exception ex)</pre> <pre><span class="lnum"> 6: </span>{</pre> <pre class="alt"><span class="lnum"> 7: </span> synthesisStream = <span class="kwrd">null</span>;</pre> <pre><span class="lnum"> 8: </span>}</pre> <pre class="alt"><span class="lnum"> 9: </span> </pre> <pre><span class="lnum"> 10: </span><span class="kwrd">if</span> (synthesisStream != <span class="kwrd">null</span>)</pre> <pre class="alt"><span class="lnum"> 11: </span>{</pre> <pre><span class="lnum"> 12: </span> MainMediaElement.AutoPlay = <span class="kwrd">true</span>;</pre> <pre class="alt"><span class="lnum"> 13: </span> MainMediaElement.SetSource(synthesisStream, synthesisStream.ContentType);</pre> <pre><span class="lnum"> 14: </span> MainMediaElement.Play();</pre> <pre class="alt"><span class="lnum"> 15: </span>}</pre> <pre><span class="lnum"> 16: </span><span class="kwrd">else</span></pre> <pre class="alt"><span class="lnum"> 17: </span>{</pre> <pre><span class="lnum"> 18: </span> MessageDialog dialog = <span class="kwrd">new</span> MessageDialog(<span class="str">"unable to synthesize text"</span>);</pre> <pre class="alt"><span class="lnum"> 19: </span> await dialog.ShowAsync();</pre> <pre><span class="lnum"> 20: </span>}</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <h2>The Contact Manager classes</h2> <p>In Windows Phone, it has been possible for some time to allow apps to manage the contacts of the user as well as manage the calendar. This feature was so far missing in Windows 8, therefore, it was hard to create apps that interact with the calendar or provide address book interactions.</p> <p>With Windows 8.1, an API is available to do this, namely the contact manager API and the appointments API. Let’s start by looking at the first one. </p> <p>In the Windows.ApplicationModel.Contacts namespace, we find all kind of classes that allow us to interact with the contact we have in the people app. The most important classes here are the Contact and the ContactManager. The Contact class represents a contact; we have all kinds of related classes such as ContactAddress, ContactEmail and ContactJobInfo. All of these allow us to represent parts of the “contact card” of a contact. That contact card is an interesting aspect of the ContactManager class. The latter allows us to enter information and we can search for a contact. Once found, we get back a contact card, shown below. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/__image_12.png"><img width="286" height="293" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/__image_thumb_5.png" alt="image" style="border-width: 0px; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-style: solid;" title="image" /></a></p> <p>Let’s see in code how we can do this.</p> <p>First, we get the contact email. For this, we use the ContactEmail class. We assign this to the Contact we also create.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>Contact contact = <span class="kwrd">new</span> Contact();</pre> <pre><span class="lnum"> 2: </span>ContactEmail contactEmail = <span class="kwrd">new</span> ContactEmail();</pre> <pre class="alt"><span class="lnum"> 3: </span>contactEmail.Address = EmailAddressTextBox.Text;</pre> <pre><span class="lnum"> 4: </span>contact.Emails.Add(contactEmail);</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>Next, we use the ContactManager class to retrieve all the information about the contact we find on the system.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>FrameworkElement fe = sender <span class="kwrd">as</span> FrameworkElement;</pre> <pre><span class="lnum"> 2: </span> </pre> <pre class="alt"><span class="lnum"> 3: </span><span class="rem">// Get the selection rect of the button pressed to show contact card.</span></pre> <pre><span class="lnum"> 4: </span>Windows.UI.Xaml.Media.GeneralTransform buttonTransform = fe.TransformToVisual(<span class="kwrd">null</span>);</pre> <pre class="alt"><span class="lnum"> 5: </span>Point point = buttonTransform.TransformPoint(<span class="kwrd">new</span> Point());</pre> <pre><span class="lnum"> 6: </span>var rect = <span class="kwrd">new</span> Rect(point, <span class="kwrd">new</span> Size(fe.ActualWidth, fe.ActualHeight));</pre> <pre class="alt"><span class="lnum"> 7: </span> </pre> <pre><span class="lnum"> 8: </span>ContactManager.ShowContactCard(contact, rect, Windows.UI.Popups.Placement.Default);</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <h2>Other noteworthy changes</h2> <p>We’ve now already covered a number of interesting classes. But there are other interesting changes.</p> <h3>Geofencing support</h3> <p>Geofencing is becoming more and more used. Perhaps first: what’s a geofence? As the word implies, it’s an imaginary fence around a certain point. When the device enters the geofence, we can choose to run code. This enables again some cool scenarios. Imagine you’re building an app for Starbucks. In the app, you can create geofences around all Starbucks’s. When the device enters a geofence, the app will be notified about this. Or you can create a geofence around yourself and when you’re in the vicinity of one of your friends, the app can be notified as well. </p> <p>When the app is notified about this, we can run code. This is possible with a new type of trigger, the LocationTrigger. With this trigger, we can trigger a background task that then will for example show a toast notification about the fact you’re close to a Starbucks to grab a cup of coffee!</p> <h3>Changes to the BackgroundTransfer API</h3> <p>When uploading or downloading files, we can use the BackgroundTransfer API. Using this API, it’s possible to register transfers with a background process that won’t be suspended when the main app goes into the suspended mode. </p> <p>Some improvements were made to this API. It’s now possible to use a BackgroundTransferGroup. This class lets us group transfers and assign them a priority. Also, we can now notify the user about the fact a transfer is finished using a tile or a toast update. The latter is an interesting feature, since previously, it wasn’t possible to let the user know that a transfer was ready.</p> <h3>POS support</h3> <p>The last interesting aspect we’ll talk about is better devices support and POS (Point-Of-Service) support. Windows 8.1 adds much better support for hardware, including USB, Bluetooth, HID (Human Interface Device) and even 3D printing. </p> <p>POS support is probably the most interesting one. It enables us to build cash register systems since we can now talk to magnetic swipe readers and barcode scanners. </p> <h2>Summary</h2> <p>In this third part, we’ve discussed some more WinRT classes that enable some cool scenarios. In the next article, we’ll discuss UX related topics, including the new size options. See you there!</p> <h2>About the author</h2> <p>Gill Cleeren is Microsoft Regional Director, Silverlight MVP, Pluralsight trainer and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina. Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd, TechDays, DevDays, NDC Oslo, SQL Server Saturday Switzerland, Silverlight Roadshow in Sweden, Telerik RoadShow UK… Gill has written 2 books: “<a href="https://www.packtpub.com/microsoft-silverlight-4-data-and-services-cookbook/book">Silverlight 4 Data and Services Cookbook</a>” and <a href="http://www.packtpub.com/microsoft-silverlight-5-data-and-services-cookbook/book">Silverlight 5 Data and Services Cookbook</a> and is author of many articles for magazines and websites. You can find his blog at <a href="http://www.snowball.be/">www.snowball.be</a>. Twitter: @gillcleeren</p> http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-3-More-WinRT-improvements.aspx editorial@silverlightshow.net (Gill Cleeren ) http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-3-More-WinRT-improvements.aspx#comments http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-3-More-WinRT-improvements.aspx Wed, 13 Nov 2013 11:57:00 GMT Windows 8.1: Play with Bluetooth Rfcomm <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-8.1-Play-with-Bluetooth-Rfcomm.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/1i0AHqE" data-text="Windows 8.1: Play with Bluetooth Rfcomm. #win8dev #win81" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Play-with-Bluetooth-Rfcomm.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-8.1-Play-with-Bluetooth-Rfcomm.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p>Scanning the new namespaces added to Windows 8.1 you'll find a new interesting surprise in the field of bluetooth support. The new operating system infact, adds support for the Bluetooth Rfcomm into the "Windows.Devices.Bluetooth.Rfcomm" namespace. The "Radio frequency communication" protocol, is a simple set of transport protocols that allow the comunication between devices using reliable data streams similar to the TCP protocol in the networking. </p> <p>What this means is that the Rfcomm protocol allows you to establish a persistent connection between two devices with a real socket. This is interesting for remote controlling devices, to acquire continuous data streams and opens to a wide set of applications that takes advantage of custom peripherals sensor.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Webinar recording: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <h4>How it works</h4> <p>Creating a connection over a Rfcomm channel is not so easy as creating a socket between two machines on the network. The very first thing you need to understand is that pairing bluetooth devices is something completely out of your control. You can only create a connection between devices that have been already paired and also if this may seems a limitation, it takes out of your control a number of boring things like security checks. The pairing of devices already implements a way to create a secure identification and you do not need to enter in this area. So, when you will scan for available devices (I'll show you this later in the article) simply expect to find devices that have successfully completed the pairing process. </p> <p>After you understand this point, the connection process is someway simple and depends on the role of the parts of the connection. Given A and B the connecting endpoints you will have a "server" (let say it is the A) and a client (B). First of all, the A endpoint needs to bind to the Bluetooth interface and opens a listening channel that await for an incoming connection. In this phase, called "advertising", the A endpoint simply signal its availability and awaits for some peer to connect. The B endpoint scans the paired devices and find the available peer. Then it try to open a socket to the listening host. At this point the server accept the connection, disposes the listener and gets the socket representing the established connection. From this point the connection is fully available and both the parts may read and write as if it is a normal ethernet connection. </p> <p>So, there are some points that may vary in these steps. As an example the listener may keep working the listening channel after a connection has been received but at the proof of facts the process of creating the data stream over bluetooth is clear. It remains to put this in practice and for this purpose, what is better that try con connect a Windows 8.1 device with a Windows Phone 8 peer?</p> <h4>Connect WP8 and W8.1 over bluetooth</h4> <p>In the following example I'll explain the code required to create an established connection between my Lumia 925 (Windows Phone 8) and the ASUS VivoTab that I recently (and successfully) upgraded to Windows 8.1. In this scenario the tablet will be the server endpoint that listen for a single connection. On the other side the Lumia 925 will try to connect to the tablet. After the connection is established every tap on the screen of the phone will be transmitted to the tablet over the bluetooth channel and it will represents the tapped point on its screen. So let start with the server part. First of all you have to setup device capabilities in the manifest. These are represented by three elements that you should add partly by the editor and partly in XML manually. Here is the resulting XML:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capabilities</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="privateNetworkClientServer"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Capability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="internetClientServer"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:DeviceCapability</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="bluetooth.rfcomm"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:Device</span> <span style="color: #ff0000;">Id</span><span style="color: #0000ff;">="any"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">m2:Function</span> <span style="color: #ff0000;">Type</span><span style="color: #0000ff;">="serviceId:A7EA96BB-4F95-4A91-9FDD-3CE3CFF1D8DA"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:Device</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">m2:DeviceCapability</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Capabilities</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>The first two capabilities can be set directly into the editor of the manifest and represents the "Internet (Client & Server)" and the "Private Networks (Client & Server)". The other part identifies the Rfcomm protocol and the Identifier of the service we are creating. This identifier is a UUID (Guid) generated by the developer and it will be used to create the Rfcomm provider. Then in the page load of the MainPage we have to start the listening channel:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async Task StartListen()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Provider = await RfcommServiceProvider.CreateAsync(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> RfcommServiceId.FromUuid(RfcommServiceUuid));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> StreamSocketListener listener = <span style="color: #0000ff;">new</span> StreamSocketListener();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> listener.ConnectionReceived += HandleConnectionReceived;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> await listener.BindServiceNameAsync(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> Provider.ServiceId.AsString(),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> var writer = <span style="color: #0000ff;">new</span> DataWriter();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> writer.WriteByte(ServiceVersionAttributeType);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> writer.WriteUInt32(ServiceVersion);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> var data = writer.DetachBuffer();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> Provider.SdpRawAttributes.Add(ServiceVersionAttributeId, data);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> Provider.StartAdvertising(listener);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--></div> </div> <p>The very first action in this code is to create an instance of a RfcommServiceProvider. This provider identifies the protocol and it will be created using the RfcommServiceUuid that we wrote in the manifest. Then it is created a StremSocketListener and it is binded to the Bluetooth channel using the provider itself. Finally, using a DataWriter some info are associated with the provider to identify the connection. More info on these attributes in this link: <a href="https://www.bluetooth.org/en-us/specification/assigned-numbers/service-discovery">https://www.bluetooth.org/en-us/specification/assigned-numbers/service-discovery</a></p> <p>Once the provider has been put in advertising mode using the StartAdvertising method, a remote device can try to open a connection (I'll speak this part in a few). When a connection is detected the ConnectionReceived event is raised and it is handled as in the following snippet:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> HandleConnectionReceived(StreamSocketListener listener, StreamSocketListenerConnectionReceivedEventArgs args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Provider.StopAdvertising();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> listener.Dispose();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> listener = <span style="color: #0000ff;">null</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">this</span>.Socket = args.Socket;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">this</span>.Reader = <span style="color: #0000ff;">new</span> DataReader(<span style="color: #0000ff;">this</span>.Socket.InputStream);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">this</span>.Run();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> }</pre> <!--CRLF--></div> </div> <p>The provider's advertising is stopped and the listener is dropped. This is because I only want to handle a single connection. You can also try to handle multiple connections leaving the advertising alive. The received socket represents the established connection and it should be used to read and write data. On the side of the Windows Phone 8 the thing is someway easy</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async Task Connect()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> PeerFinder.AlternateIdentities[<span style="color: #006080;">"Bluetooth:PAIRED"</span>] = <span style="color: #006080;">""</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> var devices = await PeerFinder.FindAllPeersAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> var device = devices.FirstOrDefault();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">if</span> (device != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">this</span>.Socket = <span style="color: #0000ff;">new</span> StreamSocket();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> await <span style="color: #0000ff;">this</span>.Socket.ConnectAsync(device.HostName, <span style="color: #006080;">"1"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">this</span>.Writer = <span style="color: #0000ff;">new</span> DataWriter(<span style="color: #0000ff;">this</span>.Socket.OutputStream);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">this</span>.bConnect.Visibility = Visibility.Collapsed;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">this</span>.LayoutRoot.Tap += LayoutRoot_Tap;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--></div> </div> <p>The PeerFinder class is used to scan the available devices, then the very first is taken. Here I assume that there is a single device available but in a real world case you should present a list of peers to the user that selects the one you want to connect to. When a device is found the socket is created and connected using the HostName. At this point the Windows 8.1 should ask the user if he accepts the connection. The rest of the code is to setup the device for the following communication. The implementation wait for taps on the screen and in case it collect the X and Y coordinates and send them along the established channel:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> LayoutRoot_Tap(<span style="color: #0000ff;">object</span> sender, System.Windows.Input.GestureEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.Writer != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> var position = e.GetPosition(<span style="color: #0000ff;">this</span>.LayoutRoot);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">this</span>.Writer.WriteInt32(1);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">this</span>.Writer.WriteInt32((<span style="color: #0000ff;">int</span>)position.X);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">this</span>.Writer.WriteInt32((<span style="color: #0000ff;">int</span>)position.Y);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> await <span style="color: #0000ff;">this</span>.Writer.StoreAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--></div> </div> <p>The code sends three integers. The first represents the command, in case of future extensions, then the coordinates. Once the message has been queued the StoreAsync method send all the packet on the stream. On the other side:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> Run()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">true</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">try</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> Command command = (Command)await <span style="color: #0000ff;">this</span>.Reader.ReadInt32Async();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">switch</span> (command)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">case</span> Command.Tap:</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> await <span style="color: #0000ff;">this</span>.HandleTap();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">break</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;">catch</span> (PeerDisconnectedException)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">return</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;">private</span> async Task HandleTap()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">int</span> x = await <span style="color: #0000ff;">this</span>.Reader.ReadInt32Async();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">int</span> y = await <span style="color: #0000ff;">this</span>.Reader.ReadInt32Async();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> await <span style="color: #0000ff;">this</span>.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> Canvas.SetLeft(ellipse, x);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> Canvas.SetTop(ellipse, y);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> }</pre> <!--CRLF--></div> </div> <p>The run method is an endless loop that listen for a integer. The integer is the command sent by the peer. Once a command is received the code selects the handler (HandleTap in this case) and it reads the following two integer. Then it moves a little circle in the given position using a canvas. Pay attention that the ReadInt32Async method is not part of the DataReader class but it is and extension method:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> async <span style="color: #0000ff;">static</span> Task<Int32> ReadInt32Async(<span style="color: #0000ff;">this</span> DataReader reader)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">uint</span> available = await reader.LoadAsync(<span style="color: #0000ff;">sizeof</span>(Int32));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">if</span> (available < <span style="color: #0000ff;">sizeof</span>(Int32))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> PeerDisconnectedException();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">return</span> reader.ReadInt32();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--></div> </div> <h4>When to use bluetooth?</h4> <p>As usual, after the technical troubles has been solved - and to prepare this example I had to solve a number of them - is it time to start thinking to possible application. Given that a number of devices supporting this protocol may already exists, I think the success it can partially depends on the ability of creating custom devices. This is not exactly my usual range of work but I hope that someone may take advantage of this article to build some astounding apps. </p> http://www.silverlightshow.net/items/Windows-8.1-Play-with-Bluetooth-Rfcomm.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Play-with-Bluetooth-Rfcomm.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Play-with-Bluetooth-Rfcomm.aspx Mon, 11 Nov 2013 12:26:00 GMT Hello Windows 8.1: what's new in the update for developers: Part 2: XAML and WinRT improvements <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-2-XAML-and-WinRT-improvements.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/18YiAtx" data-text="Hello #Windows81: what's new in the update for devs: Part 2: XAML and #WinRT improvements. #win8dev" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-2-XAML-and-WinRT-improvements.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-2-XAML-and-WinRT-improvements.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/Win81_Part%202.zip">Download the source code for this article</a></strong> </div> <p>Welcome to the second part of this article series on what’s new in the Windows 8.1 update for developers. In the first part, we’ve spent some time looking at the new features, mostly from an end-user’s perspective. We haven’t seen any code yet. That’s about to change with this second part. </p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Win8.1-Webinar.aspx">Recording of Gill's webinar: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx">Andrea Boschin's Windows 8.1 article series</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p>The goal of this article is showing you the new stuff in XAML and WinRT. The WinRT library has been extended with a great deal of extra classes and features that allow compelling experiences. Part of all that is of course XAML, in which a huge number of extra controls has been added.</p> <h2>What’s new in XAML</h2> <p>The XAML/C# combination is the preferred way of building apps for the Windows 8 store. A huge part of the apps currently in the Store has been built using XAML and C#. With the initial release of Windows 8, Microsoft spent a lot of effort on the HTML and JavaScript libraries, which resulted in a number of controls only being available for HTML/JavaScript developers and XAML developers not getting them out-of-the-box. We had to resort to external libraries (one of the important ones being the Callisto library by Tim Heuer) to get some extra controls for our apps to use.</p> <p>With Windows 8.1, this has changed quite dramatically: a huge number of extra controls has been added in XAML, bringing the 2 UI languages (XAML and HTML) on par. I’m not going to give you an overview of all XAML controls, since we already have an article on SilverlighShow that shows a lot of new controls. I’m instead going to continue where Andrea in his article left of, explaining you some interesting facts and controls.</p> <h3>WebView improvements</h3> <p>The WebView may have caused you some headache in the past. With Windows 8, this control had a bug (or was it a feature…?) that it always wanted to be the top-level control. That means that if you had a WebView on your page and an AppBar on there as well, the AppBar would never appear over the WebView, since the latter always showed as the top-level. Quite annoying, isn’t it?</p> <p>This little thing may not seem like a big deal, but for some apps that perhaps use a WebView for integrating a web experience with an app experience, this is important! Notice in the screenshot that the AppBar (in this case, it’s a CommandBar even) can sit perfectly on top of a WebView.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_________clip_image002_2.jpg"><img width="531" height="156" title="clip_image002" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image002" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_________clip_image002_thumb.jpg" /></a></p> <p>The changes for the WebView don’t stop there though. Another improvement is that we now can load HTML from more sources. Previously with Windows 8, we could load HTML using a URI (using the Navigate() method), using content from the app package or by passing the HTML and then navigating to it using NavigateToString(). In Windows 8.1, the WebView can now also load HTML from the Application Data API folders (the local and temporary ones). This way, we can create an app that perhaps downloads a ZIP file which contains HTML files, unpacks them into a sub-folder of the Local storage folder (ms-appdata:///local) and from there, reads out the HTML files using the WebView.</p> <p>In the code below, you can see how we are reading out some HTML located in a subdirectory of the Local Storage folder. We can only get to the HTML file by specifically passing the URL as the parameter for the Navigate() method.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">string</span> url = <span class="str">"ms-appdata:///local/Htmls/test.html"</span>;</pre> <pre><span class="lnum"> 2: </span> </pre> <pre class="alt"><span class="lnum"> 3: </span>MyWebView.Navigate(<span class="kwrd">new</span> Uri(url));</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>Furthermore, the WebView has been enhanced to support the following as well:</p> <ul> <li>Taking a screenshot of the content of the WebView and saving it to a local image (for example, a png file). This is supported by using the WebView’s CapturePreviewToStreamAsync() method</li> <li>More information on the event lifecycle of the loaded page becomes available for the app using it through new events such as NavigationStarting, ContentLoading, DOMContentLoaded and NavigationCompleted. This gives the surrounding app more options to display for example loading icons while the page is loading</li> <li>Notifying the app about “changes” in the HTML. Suppose the app needs to be notified about the user completing a field in the HTML page. We can use ScriptNotify to enable this event-raising in the app. The page can send back some data such as a string with this as well.</li> </ul> <p>There are some other (mostly less important) changes made to the WebView API, check out the MSDN page for this control if you want to read all the supported items: <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.aspx">http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.aspx</a></p> <h3>Data binding improvements</h3> <p>Data binding has been one of my favourite features in XAML for years. When Windows 8 was released, some interesting features we had with Silverlight weren’t available yet. In fact, I always compared the Windows 8 data binding options to be on-par with only Silverlight 3. This means that a lot of cool features we got in Silverlight 4 and 5 were still missing.</p> <p>Windows 8 brings some new options, mostly things that we got with Silverlight 4. More specifically, we now have support for TargetNullValue, FallbackValue and UpdateSourceTrigger in Windows 8.1. Let’s take a look at these in a bit more detail.</p> <h4>FallbackValue</h4> <p>Assume the following, very simple class structure:</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/______clip_image003_2.png"><img width="275" height="361" title="clip_image003" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image003" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/______clip_image003_thumb.png" /></a></p> <p>Assume that we have the following UI.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">Grid</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 2: </span> <span class="kwrd"><</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd"><</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="50"</span><span class="kwrd">></</span><span class="html">RowDefinition</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 4: </span> <span class="kwrd"><</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="50"</span><span class="kwrd">></</span><span class="html">RowDefinition</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 5: </span> <span class="kwrd"><</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="50"</span><span class="kwrd">></</span><span class="html">RowDefinition</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 6: </span> <span class="kwrd"><</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="50"</span><span class="kwrd">></</span><span class="html">RowDefinition</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 7: </span> <span class="kwrd"><</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="50"</span><span class="kwrd">></</span><span class="html">RowDefinition</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 8: </span> <span class="kwrd"></</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 9: </span> <span class="kwrd"><</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 10: </span> <span class="kwrd"><</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="200"</span><span class="kwrd">></</span><span class="html">ColumnDefinition</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 11: </span> <span class="kwrd"><</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="200"</span><span class="kwrd">></</span><span class="html">ColumnDefinition</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 12: </span> <span class="kwrd"></</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 13: </span> <span class="kwrd"><</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="First name"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="0"</span><span class="kwrd">></</span><span class="html">TextBlock</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 14: </span> <span class="kwrd"><</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="Last name"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBlock</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 15: </span> <span class="kwrd"><</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="Function"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="2"</span><span class="kwrd">></</span><span class="html">TextBlock</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 16: </span> <span class="kwrd"><</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="Employee badge"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="3"</span><span class="kwrd">></</span><span class="html">TextBlock</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 17: </span> <span class="kwrd"><</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="Company car type"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="4"</span><span class="kwrd">></</span><span class="html">TextBlock</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 18: </span> <span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding FirstName}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="0"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 19: </span> <span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding LastName}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 20: </span> <span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding EmployeeBadgeId}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="2"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 21: </span> <span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding Function}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="3"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 22: </span> <span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding CompanyCarType}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="4"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 23: </span><span class="kwrd"></</span><span class="html">Grid</span><span class="kwrd">></span></pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>If we now bind to a Person instance, we’ll get a lot of binding errors, as can be seen in the screenshot below. It’s quite logical we are getting these, since we’re binding to properties that don’t exist, which will logically result in a binding error.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_______clip_image004_2.png"><img width="496" height="96" title="clip_image004" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image004" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_______clip_image004_thumb.png" /></a></p> <p>We can now make use of the FallBackValue property. The value we specify in a binding for this property will be shown when the binding fails (for whatever reason that may be).</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding FirstName}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="0"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 2: </span><span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding LastName}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 3: </span><span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding EmployeeBadgeId, FallbackValue='Not an employee'}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="2"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre><span class="lnum"> 4: </span><span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding Function, FallbackValue='Not an employee'}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="3"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> <pre class="alt"><span class="lnum"> 5: </span><span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding CompanyCarType, FallbackValue='Not a manager'}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="4"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>The following will now display. Note that we could have gotten the same result by using a converter. The FallbackValue is just a bit of a shortcut in order not to have to write a converter.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image006_2.jpg"><img width="416" height="299" title="clip_image006" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image006" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image006_thumb.jpg" /></a></p> <h4>TargetNullValue</h4> <p>Assume now that we are binding to a value which evaluates to null (the Manager hasn’t received a company car sadly).</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>Manager m = <span class="kwrd">new</span> Manager();</pre> <pre><span class="lnum"> 2: </span>m.FirstName = <span class="str">"Gill"</span>;</pre> <pre class="alt"><span class="lnum"> 3: </span>m.LastName = <span class="str">"Cleeren"</span>;</pre> <pre><span class="lnum"> 4: </span>m.Function = <span class="str">"Director"</span>;</pre> <pre class="alt"><span class="lnum"> 5: </span>m.EmployeeBadgeId = <span class="str">"12345"</span>;</pre> <pre><span class="lnum"> 6: </span>m.CompanyCarType = <span class="kwrd">null</span>;</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>We can again display a message of choice by using the TargetNullValue as follows:</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding CompanyCarType, FallbackValue='Not a manager', TargetNullValue='No company car for this manager'}"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="4"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>The result is shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/__clip_image008_2.jpg"><img width="422" height="115" title="clip_image008" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image008" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/__clip_image008_thumb.jpg" /></a></p> <p>The TargetNullValue is another property on the Binding new in 8.1. It allows us to specify what has to happen when the property we’re binding too evaluates to null.</p> <h4>UpdateSourceTrigger</h4> <p>The last new property we’re getting related to data binding is the UpdateSourceTrigger. Previously, when using a two-way binding, the source was always updating automatically (so when the value in the UI was changed by the user, the source also updated). UpdateSourceTrigger can change that. When we set it to Explicit, we can specify when we want the update of the source to take place.</p> <p>Take a look at the following XAML code. Notice that the Mode for the binding has now been set to TwoWay and the UpdateSourceTrigger is Explicit. This means that although the binding is TwoWay, changing the value won’t happen directly anymore.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">="CompanyCarTextBox"</span> <span class="attr">Text</span><span class="kwrd">="{Binding MyManager.CompanyCarType, Mode=TwoWay, </span></pre> <pre><span class="lnum"> 2: </span> FallbackValue='Not a manager', TargetNullValue='No company car for this manager', </pre> <pre class="alt"><span class="lnum"> 3: </span> UpdateSourceTrigger=Explicit}" <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="4"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">></</span><span class="html">TextBox</span><span class="kwrd">></span></pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>Instead, the value will now only update when we want it too. We can do this using the following code. </p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">private</span> <span class="kwrd">void</span> UpdateButton_Click(<span class="kwrd">object</span> sender, RoutedEventArgs e)</pre> <pre><span class="lnum"> 2: </span>{</pre> <pre class="alt"><span class="lnum"> 3: </span> var expression = CompanyCarTextBox.GetBindingExpression(TextBox.TextProperty);</pre> <pre><span class="lnum"> 4: </span> expression.UpdateSource();</pre> <pre class="alt"><span class="lnum"> 5: </span>}</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>The other values for UpdateSourceTrigger are Default and PropertyChanged. Most often, PropertyChanged is the default and is actually the same as we had previously.</p> <h3>RenderTargetBitmap</h3> <p>We will close this article by looking at another UI related class in WinRT namely the RenderTargetBitmap. This class is one of my favourite additions to Windows 8.1 since it enables a lot of cool scenarios, such as a meme generator application.</p> <p>The RenderTargetBitmap class enables us to capture just any XAML element and export it to an image, for example a *.png that we then can save to the local disk. Since the XAML element itself can be a container element as well (like a Grid), it’s perfectly possible to allow the user to create an interface (a meme, a Christmas card…) and then export this to a physical file from the app using a FileSavePicker. Let’s take a look at how this controls works. We’ll build a very basic meme generator, based on the <em>Most Interesting Man</em> meme, as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image010_2.jpg"><img width="286" height="458" title="clip_image010" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image010" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_clip_image010_thumb.jpg" /></a></p> <p>For the XAML, take a look at the code for the article. We’ll focus on the code here.When clicking on the Export button, we are first instantiating the RenderTargetBitmap. It is passed through the RenderAsync method, the name of the element we want to export. Once rendered using the async RenderAsync, we use the GetPixelsAsync to get access to the pixels that were rendered.</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>RenderTargetBitmap renderTargetBitmap = <span class="kwrd">new</span> RenderTargetBitmap();</pre> <pre><span class="lnum"> 2: </span>await renderTargetBitmap.RenderAsync(MemeGrid);</pre> <pre class="alt"><span class="lnum"> 3: </span>var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <p>After this, we can ask the user to select a location to save the file using a FileSavePicker.</p> <div class="csharpcode"> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span>var fileSavePicker = <span class="kwrd">new</span> FileSavePicker();</pre> <pre><span class="lnum"> 2: </span>fileSavePicker.DefaultFileExtension = <span class="str">".png"</span>;</pre> <pre class="alt"><span class="lnum"> 3: </span>fileSavePicker.FileTypeChoices.Add(<span class="str">".png"</span>, <span class="kwrd">new</span> List<<span class="kwrd">string</span>> { <span class="str">".png"</span> });</pre> <pre><span class="lnum"> 4: </span>fileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;</pre> <pre class="alt"><span class="lnum"> 5: </span>fileSavePicker.SuggestedFileName = <span class="str">"Meme.png"</span>;</pre> <pre><span class="lnum"> 6: </span> </pre> <pre class="alt"><span class="lnum"> 7: </span>var saveFile = await fileSavePicker.PickSaveFileAsync();</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> </div> <p>With this in place, we can now write the image pixels to the selected file. We first get in the StorageFile and open it. Then we create the encoder and pass it some values to indicate the parameters for the image creation (image size, DPI…). Finally, the FlushAsync will flush the image data to the physical file. We now have a saved image on disk on the selected location!</p> <div class="csharpcode"> <pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">if</span> (saveFile != <span class="kwrd">null</span>)</pre> <pre><span class="lnum"> 2: </span>{</pre> <pre class="alt"><span class="lnum"> 3: </span> <span class="kwrd">using</span> (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))</pre> <pre><span class="lnum"> 4: </span> {</pre> <pre class="alt"><span class="lnum"> 5: </span> var imageEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);</pre> <pre><span class="lnum"> 6: </span> </pre> <pre class="alt"><span class="lnum"> 7: </span> imageEncoder.SetPixelData(</pre> <pre><span class="lnum"> 8: </span> BitmapPixelFormat.Bgra8,</pre> <pre class="alt"><span class="lnum"> 9: </span> BitmapAlphaMode.Ignore,</pre> <pre><span class="lnum"> 10: </span> (<span class="kwrd">uint</span>)renderTargetBitmap.PixelWidth,</pre> <pre class="alt"><span class="lnum"> 11: </span> (<span class="kwrd">uint</span>)renderTargetBitmap.PixelHeight,</pre> <pre><span class="lnum"> 12: </span> DisplayInformation.GetForCurrentView().LogicalDpi,</pre> <pre class="alt"><span class="lnum"> 13: </span> DisplayInformation.GetForCurrentView().LogicalDpi,</pre> <pre><span class="lnum"> 14: </span> pixelBuffer.ToArray());</pre> <pre class="alt"><span class="lnum"> 15: </span> </pre> <pre><span class="lnum"> 16: </span> await imageEncoder.FlushAsync();</pre> <pre class="alt"><span class="lnum"> 17: </span> }</pre> <pre><span class="lnum"> 18: </span>}</pre> </div> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } </style> <h2>Summary</h2> <p>In this second part, we looked at some interesting, new aspects from XAML and we started looking at some new classes part of WinRT as well. The next article in this series will build on this, exploring some more interesting classes in the framework. I hope to see you there as well!</p> <h2>About the author</h2> <p>Gill Cleeren is Microsoft Regional Director, Silverlight MVP, Pluralsight trainer and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina. Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd, TechDays, DevDays, NDC Oslo, SQL Server Saturday Switzerland, Silverlight Roadshow in Sweden, Telerik RoadShow UK… Gill has written 2 books: “<a href="https://www.packtpub.com/microsoft-silverlight-4-data-and-services-cookbook/book">Silverlight 4 Data and Services Cookbook</a>” and <a href="http://www.packtpub.com/microsoft-silverlight-5-data-and-services-cookbook/book">Silverlight 5 Data and Services Cookbook</a> and is author of many articles for magazines and websites. You can find his blog at <a href="http://www.snowball.be/">www.snowball.be</a>. Twitter: @gillcleeren</p> http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-2-XAML-and-WinRT-improvements.aspx editorial@silverlightshow.net (Gill Cleeren ) http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-2-XAML-and-WinRT-improvements.aspx#comments http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-2-XAML-and-WinRT-improvements.aspx Wed, 06 Nov 2013 11:59:00 GMT Hello Windows 8.1: what's new in the update for developers: Part 1: Overview of the new features <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-1-Overview-of-the-new-features.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-1-Overview-of-the-new-features.aspx" data-count="horizontal" data-text="Hello #Windows81: what's new in the update for devs: Part 1: Overview of the new features. #win8dev" data-url="http://slshow.net/1g8TpNe">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-1-Overview-of-the-new-features.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p>Hi and welcome to a new series of articles here on SIlverlightShow where we will give an overview of the new concepts and changes in the first big update of Windows 8, known to mankind as Windows 8.1. Over the next couple of articles, we will take a look at the things that have changed. You’ll soon understand that while the changes you’ll have to do in your code are often subtle, they will lead to a much better user experience which is in-line with the new version of the OS. </p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/news/Latest-and-Greatest-in-Windows-8.1-for-Developers.aspx">Gill's webinar on Oct 30: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx">Andrea Boschin's Windows 8.1 article series</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p>In this first part, we are going to introduce the new version and see what has changed. After that, we’ll explore how we can use these new functions from a developer’s perspective!</p> <h2>Welcome to 8.1</h2> <p>As mentioned, we are first going to take a look at all the new stuff in this release of Windows. We’re going to do that from the end-user’s perspective. Of course, we’ll explore the dev features, but that’s for later. </p> <p>I want to start with this important statement, which I’m going to refer back to from the rest of the articles several times: <strong>Windows 8.1 is JUST an update</strong>, nothing more. The update is “<strong>almost non-breaking</strong>”. With “almost non-breaking”, I mean the following. Code-wise, all your Windows 8 code will still run, there’s no problem there. Some Windows 8 APIs are deprecated, but they aren’t removed from the API. However, in terms of user experience, things have changed. If you don’t update your application code to 8.1, your users will get a less-than-optimal experience from your app, which is something I assume you don’t want. So, code-wise, no breaking changes, but in terms of user experience, there are some things you need to take into consideration to make sure that your users are getting the best experience you can create.</p> <h3>The new Start screen</h3> <p>The very first thing you’ll see after you have upgraded to (or for that matter, just installed) Windows 8.1, is the new Start screen. I’ve posted a screenshot of my current Start screen, which should give you an idea of what has changed in that area.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/________clip_image002_2.jpg"><img width="609" height="324" title="clip_image002" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image002" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/________clip_image002_thumb.jpg" /></a></p> <p>Probably the most string thing here is the background. Indeed, that is not one of the included Start screen backgrounds we had with Windows 8. Instead, this is the background of my desktop environment. One of the main complaints that people had with Windows 8 was that it somehow felt as if we had 2 operating systems running next to each other. Just by adding this – let’s face it – small change, the “two operating systems” already look a lot more integrated!</p> <h3>New tile sizes</h3> <p>Another thing we can get from the screenshot above is that we can now have several types of tiles which weren’t previously available in Windows 8. With Windows Phone 8, Microsoft allowed phone users to create small and large tiles, in addition to the previously available square and wide tiles. In Windows 8.1, Microsoft did the same for Windows 8: we now have 4 tile sizes available. This allows the user to customize his Start screen more easily to his needs.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image003_2.png"><img width="218" height="225" title="clip_image003" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px;" alt="clip_image003" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image003_thumb.png" /></a></p> <p>The small tile size allows us to create an area in the Start screen where we pin tiles of which we don’t expect (or basically care for) live tile updates. Indeed, the small tile size doesn’t support tile updates, they only support badge updates. In the above screenshot, you can see my mail tile having a badge update: the number 24 indicates I have to get back reading my email since I have 24 unread mails! In general, this small tile size is ideal for apps such as Internet Explorer or regular desktop apps which don’t utilize the tile functionality. </p> <p>The other new tile size is the large tile, as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/______clip_image004_2.png"><img width="244" height="242" title="clip_image004" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px;" alt="clip_image004" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/______clip_image004_thumb.png" /></a></p> <p>This new size allows apps to give more information to the user, such as in the case of the weather apps, give an overview of the weather in more cities.</p> <p>The new tile sizes have an effect on existing apps: the tile template names have changed, causing some minor issues if your app already uses tiles now. We’ll take a look at what we need to do to fix all this in a later article.</p> <h3>The Return of the Start button</h3> <p>The above header sounds a bit like a bad Hollywood movie but again it’s in important aspect when it comes to giving the users what they want. A lot of fuzz was created with Windows 8 regarding the fact that the user experience was too different from what we had previously. Probably the silliest of all the remarks being made was the fact that the Start button (and the Start menu) had gone. Although they hadn’t. They were simply replaced by a) the lower left pixels on your screen and b) the Start screen.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image005_2.png"><img width="125" height="45" title="clip_image005" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px;" alt="clip_image005" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image005_thumb.png" /></a></p> <p>Many internet-fights have been fought over this matter and Microsoft decided in Windows 8.1 that the change was perhaps a bit too dramatic. They have created a compromise: the Start button is back and it takes us to the modern (and in my opinion, much better) Start screen.</p> <p>From a developer’s perspective, there’s really no value here. But for many users, this might be a big deal, resulting in a higher adoption rate for Windows 8 and thus resulting in more app installs for you! So good news anyway!</p> <h3>The new app sizes</h3> <p>One of the cool features of Windows 8 was the ability to run an application in Snap view. When snapped, the application was always 320px wide (x scale factor if any). This view was certainly interesting to allow the user to have more than one app open on-screen. Typically, apps that offer a monitoring activity such as a Twitter app included this view (it’s a Store requirement to have this view but not all apps did something useful with it). Also media apps often had this view to allow the user to continue viewing a video while doing some work.</p> <p>In this area, an application could thus be in Full screen mode, in Snapped mode or in Filled mode (the remainder of the screen when having an another app snapped on screen).</p> <p>Windows 8.1 gives us more flexibility in this area. It’s now possible to have 2 (or more, depending on your screen size and resolution) apps on screen with different resolutions. The minimum supported size is now 500px, instead of 320px. This means that your app should give the user a great experience on any resolution from 500px upwards. Take a look at the screenshots below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image007_2.jpg"><img width="522" height="293" title="clip_image007" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image007" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image007_thumb.jpg" /></a></p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image009_2.jpg"><img width="523" height="290" title="clip_image009" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image009" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image009_thumb.jpg" /></a></p> <p>On my Surface here, I can have 2 apps running side-by-side, resizing them like I want. If I attach more external displays, I can run more (up to 10 apps) at the same time.</p> <p>This is another aspect where I reckon that the change is almost non-breaking. If you run a Windows 8 app on Windows 8.1, the snap view will still work, but in a compatibility more (using black bars for all sizes between 320 and 500px). It’s therefore recommended that you upgrade your app so it supports and handles these new size options correctly. We’ll show how to do that later!</p> <h3>Search has changed</h3> <p>In Windows 8, Microsoft recommended that searching was done using the Search charm. This way, we can offer the user a unified searching model. While the idea was great, a lot of people struggled with the Search in Windows 8. They couldn’t find it, which was probably because it was hidden behind a charm and when no one tells the user to look there for the Search option, he simply dismisses the app.</p> <p>In Windows 8.1, Microsoft has cut back on the guidelines around Search, now allowing us to add a regular search box in our apps. The options we have with this new control are still pretty much the same but they are now wrapped in a control instead of being addressable through the Search Pane. This effectively means that we can still send suggestions and recommendations to the search control.</p> <p>Take for example the Music app, which now features a Search box control.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image010_2.png"><img width="195" height="244" title="clip_image010" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px;" alt="clip_image010" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image010_thumb.png" /></a></p> <p>We can see that the control is indeed part of the regular page UI and still offers the same experience as before. </p> <p>In one of the coming articles, we’ll see that how we can work with the new Search. We’ll explore what happens when you still want to support the Search contract as well or what happens when you run a Windows 8 app that’s built around Search on Windows 8.1.</p> <h3>More chrome</h3> <p>This last topic is a bit more design-linked than the previous ones. You probably know that for Windows 8, Microsoft has developed a design language (first known as Metro, later on renamed to Modern UI). This language was quite strict and one of the main aspects of the language was the limitation of use of chrome, the so-called content-before-chrome principle. This basically said that the user should see content, that’s what the user is using the application for. Don’t bother showing the user all kinds of buttons and toolbars, they create nothing more than a distraction and take away screen estate that should be used to display content.</p> <p>For Windows 8.1, Microsoft has created an evolution of these guidelines. Content is still very important, but some more chrome is making its way into the applications. We can even see that even in the built-in apps that come with a default Windows 8.1 installation. </p> <p>Take again the music app and notice that we now have a sort of tab navigation on the left. That wasn’t a recommendation to use before in Windows 8.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image012_2.jpg"><img width="327" height="395" title="clip_image012" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image012" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/clip_image012_thumb.jpg" /></a></p> <p>Another app where this is clearly visible, is the Health and Fitness app. Take a look at the screenshot below. The part on the left is nothing short of a menu of buttons/options that allow us to navigate to different parts of the application.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image014_2.jpg"><img width="406" height="245" title="clip_image014" style="border: 0px none; background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px;" alt="clip_image014" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/___clip_image014_thumb.jpg" /></a></p> <p>Even the Search control we saw in the previous topic is an evolution. Previously, Microsoft recommended against using a Search box within the app; now they recommend doing so.</p> <p>Again, for existing applications, this is not really an issue. However, once more apps start changing their UI slightly, it’s recommended doing so for your apps as well. Otherwise, the user may find your app difficult to navigate, resulting in less positive reviews.</p> <h2>Summary</h2> <p>In this first part of this new article series, we’ve looked at the user’s perspective of what changed in Windows 8.1. Starting with the next article, we’re going to see how we can use these from our own apps. Stay tuned!</p> <h2>About the author</h2> <p>Gill Cleeren is Microsoft Regional Director, Silverlight MVP, Pluralsight trainer and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina. Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd, TechDays, DevDays, NDC Oslo, SQL Server Saturday Switzerland, Silverlight Roadshow in Sweden, Telerik RoadShow UK… Gill has written 2 books: “<a href="https://www.packtpub.com/microsoft-silverlight-4-data-and-services-cookbook/book" target="_blank">Silverlight 4 Data and Services Cookbook</a>” and <a href="http://www.packtpub.com/microsoft-silverlight-5-data-and-services-cookbook/book" target="_blank">Silverlight 5 Data and Services Cookbook</a> and is author of many articles for magazines and websites. You can find his blog at <a href="http://www.snowball.be/" target="_blank">www.snowball.be</a>. Twitter: @gillcleeren</p> http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-1-Overview-of-the-new-features.aspx editorial@silverlightshow.net (Gill Cleeren ) http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-1-Overview-of-the-new-features.aspx#comments http://www.silverlightshow.net/items/Hello-Windows-8.1-what-s-new-in-the-update-for-developers-Part-1-Overview-of-the-new-features.aspx Tue, 29 Oct 2013 12:17:00 GMT Windows 8.1: Location-aware apps - Part #2: Working in background <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-2-working-in-background.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-2-working-in-background.aspx" data-count="horizontal" data-text="Windows 8.1: Location-aware apps - Part #2: Working in background. #win8dev" data-url="http://slshow.net/1dh28tc">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-2-working-in-background.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/news/Latest-and-Greatest-in-Windows-8.1-for-Developers.aspx">Free webinar on Oct 30: <strong>Latest & greatest in Win8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">In the previous article I've talked about the basic location api and I've introduced the geo-fencing features that are new in Windows 8.1. These API, partly already available in the very first release of the operating system, are for sure a interesting opportunity to build location aware applications, taking the full advantage from the "mobility" of modern devices.</p> <p style="text-align: justify;">The API that I've explained, are all made to be used when you application is running, but as you probably figured out, this is not exactly the most common situation for our applications.</p> <h3 style="text-align: justify;">Location aware background tasks</h3> <p style="text-align: justify;">If you try to stop and think about the lifetime of an application, you probably will find that also when they are used a lot, for the major part of their life they are switched off, probably for more time than they are running. In a tracking application that should collect positions of the device along the time, this is not an ideal situation.</p> <p style="text-align: justify;"> If you think that a Windows 8.1 device can run a maximum of 4 applications at a time, under particolar conditions, you understand that it is completely unacceptable to track positions only when the application is running. Even when snapped, there are a number of events that can make your app going to sleep and then stopping to track. </p> <p style="text-align: justify;"><img width="312" height="325" title="image" style="margin: 0px 0px 0px 15px; border: 0px none currentcolor; display: inline; background-image: none; float: right;" alt="image" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_7c9d4f9b-6216-46e4-9e58-2762a9bb5f33.png" />For this reason with Windows 8.1 they added the capability of tracking the position in a background task. Just for remember, a background task is a separate task that is started when the application is run for the first time and then it remains active also if the application has been closed or has been put to sleep. Together with the common background task that we know in Windows 8, the new relase added a new type that is dedicated to location services. To activate this kind of background service you have to open the manifest in Visual Studio and go to the "Declarations" tab. Then add a "Background Service" and select the type on the right side. </p> <p style="text-align: justify;">I'll return in a few on the registration topic. This is infact the last action you have to accomplish just before deploy the application and try to run. Before this you have to phisically create the background task. For location purposes, there are two type of tasks you can use: a "Timer", used to collect locations as an example, and a "Location" task that is mostly used to support geofencing. Both the types must be created using a class declared into a Windows Runtime Component. This is an important point because nothing prevents to create the task in a class library but is will not work as expected, so please be always careful in this point.</p> <p style="text-align: justify;">So first of all let create a Windows Runtime Component, remember to reference it from your application project and then you can create your background task skeleton inside of it: </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">sealed</span> <span style="color: #0000ff;">class</span> LocationService : IBackgroundTask</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Run(IBackgroundTaskInstance taskInstance)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> var deferral = taskInstance.GetDeferral();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">try</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #008000;">// do the work here...</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">finally</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> deferral.Complete();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The background task, when invoked take a reference to a deferral. This is used to communicate to the runtime when the task has completed but remember, it does not give you more time than the few seconds granted by the operating system. Then you have to manually register the background task in code. You call your registration service when the user asks to run the background service. You have always to create also the code to unregister the background task in the case the user would not want to run the background task anymore.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">string</span> LocationServiceName = <span style="color: #006080;">"LocationService"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">string</span> LocationServiceEntryPoint = <span style="color: #006080;">"XPG.Geolocation.Tasks.LocationService"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">private</span> IBackgroundTaskRegistration GeoLocationTask { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> RegisterBackgroundTask()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">this</span>.GeoLocationTask = BackgroundTaskRegistration.AllTasks.FirstOrDefault(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> bt => bt.Value.Name == LocationServiceName).Value;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.GeoLocationTask == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> BackgroundAccessStatus backgroundAccessStatus = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> await BackgroundExecutionManager.RequestAccessAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;">if</span> (backgroundAccessStatus == BackgroundAccessStatus.Unspecified ||</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> backgroundAccessStatus == BackgroundAccessStatus.Denied)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> Exception(<span style="color: #006080;">"Error registering background task: not authorized"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> BackgroundTaskBuilder taskBuilder = <span style="color: #0000ff;">new</span> BackgroundTaskBuilder();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> taskBuilder.Name = LocationServiceName;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> taskBuilder.TaskEntryPoint = LocationServiceEntryPoint;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> TimeTrigger timeTrigger = <span style="color: #0000ff;">new</span> TimeTrigger(15, <span style="color: #0000ff;">false</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> taskBuilder.SetTrigger(timeTrigger);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #0000ff;">this</span>.GeoLocationTask = taskBuilder.Register();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> <span style="color: #0000ff;">this</span>.GeoLocationTask.Completed += OnCompleted;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> UnregisterBackgroundTask()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.GeoLocationTask != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> <span style="color: #0000ff;">this</span>.GeoLocationTask.Completed -= OnCompleted;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> <span style="color: #0000ff;">this</span>.GeoLocationTask.Unregister(<span style="color: #0000ff;">true</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> <span style="color: #0000ff;">this</span>.GeoLocationTask = <span style="color: #0000ff;">null</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> OnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> Debug.WriteLine(<span style="color: #006080;">"Task {0} has completed"</span>, sender.Name);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">In the very first lines of code I check if the task has already registered. This is important to avoid duplicate instances that can lead to confusion while running and debugging. Then, if the task has not registered, I request the access to background services. This presents to the user the common request that asks if he consents to run the task in background. In the case the user denies we have to gracefully exit from registration and continue to run the application. Differently, using the BackgroundTaskBuilder the task is created and registered. Pay attention to the name of the task and to the Task entry point because is it often cause of not working tasks. Associated to this task there is a TimeTrigger, that will raise the task once every 15 minutes. The geo location task has also a completed event that is useful to update the user interface when the application is running and the task completes its work. Inside the Location task I get the location and store it wherever I want:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> CancellationTokenSource CancellationTokenSource { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">public</span> async <span style="color: #0000ff;">void</span> Run(IBackgroundTaskInstance taskInstance)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> var deferral = taskInstance.GetDeferral();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">try</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.CancellationTokenSource == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">this</span>.CancellationTokenSource = <span style="color: #0000ff;">new</span> CancellationTokenSource();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> taskInstance.Canceled += taskInstance_Canceled;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> Geolocator locator = <span style="color: #0000ff;">new</span> Geolocator();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> Geoposition position = await locator.GetGeopositionAsync()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> .AsTask(<span style="color: #0000ff;">this</span>.CancellationTokenSource.Token);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;">this</span>.StoreLastPosition(DateTime.Now, position.Coordinate.Point);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;">catch</span> (Exception ex)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> Debug.WriteLine(ex.Message);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">finally</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> taskInstance.Canceled -= taskInstance_Canceled;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> deferral.Complete();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> taskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.CancellationTokenSource != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> <span style="color: #0000ff;">this</span>.CancellationTokenSource.Cancel();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> <span style="color: #0000ff;">this</span>.CancellationTokenSource = <span style="color: #0000ff;">null</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> StoreLastPosition(DateTime dateTime, Geopoint geopoint)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Inside the Run method a CancellationToken is created to be able to stop che geo location task if a cancellation occurs before the operation is completed. Given that a background task can run only for a limited time, it is required to always have an handle that allows to stop the asynchronous operation if it is required. In the Cancel event the CancellationToken is Canceled causing the Task to exit. </p> <h3 style="text-align: justify;">Geofencing in background</h3> <p style="text-align: justify;">Upto here we have implemented a background task using a TimeTrigger. This kind of trigger is not new to Windows 8.1. In the new release of the operating system they added also a LocationTrigger. A LocationTrigger is strictly related to the geofencing system. It triggers the background task execution when the status of a geofence, registered with the GeofenceMonitor has changed. This is really awesome give that we can use the GeofenceMonitor as I've explained in the previous number of this series and then attach a LocationTrigger to a background task and get notifications when the device enters or exits the geofences. Here is how to register the Location trigger.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> RegisterGeofenceBackgroundTask()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">this</span>.GeoLocationTask = BackgroundTaskRegistration.AllTasks.FirstOrDefault(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> bt => bt.Value.Name == GeofenceServiceName).Value;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.GeoFenceTask == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> BackgroundAccessStatus backgroundAccessStatus =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> await BackgroundExecutionManager.RequestAccessAsync();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">if</span> (backgroundAccessStatus == BackgroundAccessStatus.Unspecified ||</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> backgroundAccessStatus == BackgroundAccessStatus.Denied)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> Exception(<span style="color: #006080;">"Error registering background task: not authorized"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> BackgroundTaskBuilder taskBuilder = <span style="color: #0000ff;">new</span> BackgroundTaskBuilder();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> taskBuilder.Name = GeofenceServiceName;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> taskBuilder.TaskEntryPoint = GeofenceServiceEntryPoint;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> LocationTrigger locationTrigger = <span style="color: #0000ff;">new</span> LocationTrigger(LocationTriggerType.Geofence);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> taskBuilder.SetTrigger(locationTrigger);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;">this</span>.GeoFenceTask = taskBuilder.Register();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;">this</span>.GeoFenceTask.Completed += OnCompleted;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The code is pretty similar to the one used for a TimeTrigger but it differs for the declaration of the LocationTrigger. This kind of trigger only accept a LocationTriggerType equals to Geofence that is the sole available at the moment. Here we do not declare any geofence to monitor. These have to be already added to the geofence monitor previously. So the trigger will fire when the monitor raises an event of GeofenceStateChanged. </p> <p style="text-align: justify;">The background task is in charge of finding what is the geofences that have been affected by this change. For this purpose you can use the ReadReports method.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">sealed</span> <span style="color: #0000ff;">class</span> GeofenceService : IBackgroundTask</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> CancellationTokenSource CancellationTokenSource { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Run(IBackgroundTaskInstance taskInstance)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> var deferral = taskInstance.GetDeferral();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">try</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">this</span>.EvaluateGeofences();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">catch</span> (Exception ex)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> Debug.WriteLine(ex.Message);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">finally</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> deferral.Complete();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> EvaluateGeofences()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">foreach</span> (var report <span style="color: #0000ff;">in</span> GeofenceMonitor.Current.ReadReports())</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> Debug.WriteLine(<span style="color: #006080;">"Geofence {0} changed to {1}"</span>, report.Geofence.Id, report.NewState);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The ReadReports method returns all the changes occured since last time the method was called. This is really perfect to get a list of events that we can evaluate to understand what is the one that has triggered the background service.</p> <h3 style="text-align: justify;">Improved location-awareness</h3> <p style="text-align: justify;">In this article and in the previous, I've explained how to take advantage of location services that are exposed by Windows 8 and recently powered by the 8.1 release. It is sure that the recent release added some very important trick for the development of location-aware apps. The geofencing is really a beautiful feature that can lead to a number of applications, also for business purposes. I hope that next releases also add some more control to the location aspects, to give another major gear to this category of apps.</p> http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-2-working-in-background.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-2-working-in-background.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-2-working-in-background.aspx Mon, 28 Oct 2013 12:41:00 GMT Windows 8.1: Location-aware apps - Part #1: What's new in geolocation <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-1-What-s-new-in-geolocation.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/1a6ZIwH" data-text="Windows 8.1: Location-aware apps - Part #1: What's new in geolocation. #win8dev" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-1-What-s-new-in-geolocation.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-1-What-s-new-in-geolocation.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/news/Latest-and-Greatest-in-Windows-8.1-for-Developers.aspx">Free webinar on Oct 23: <strong>Latest & greatest in Windows 8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p>Mobile devices have grown a lot in the last years and a lot of practical applications are developing a huge market around them. One of the most important points that made the success of mobile devices is the availability of sensor that uses the Global Positioning System (GPS) to detect the geographic location of the devices. GPS Sensor is supported in Windows Store apps since the very first release but it has got a number of new and important features that maximizes the capabilities of your device giving new horizons to your ideas.</p> <h3>At the basic.</h3> <p>People that build a GPS application in Windows 8 knows that the only class used by the location system is the Geocoordinate. This type contains a number of properties related to the location: Latitude, Longitude and Altitude describes the tridimensional position detected by the sensor, heading (direction) and speed add some more useful information that are calculated on the basis of multiple sampling. In Windows 8.1, all these properties still exist but they have been deprecated. If you try to use them you get a warning with this text: "Altitude may be altered or unavailable after Windows 8.1. Instead, use Geocoordinate.Point". </p> <p>The following diagram shows the types involved in this changes: The new "Point" property in the Geocoordinate class opens to a new interesting perpective, just because it opens to new future extensions. At the basic of this property there is the IGeoShape interface that, as the name suggests, may describe complex shapes and not only points. </p> <p><img width="706" height="348" title="image" style="margin: 5px auto 0px; border: 0px none currentcolor; float: none; display: block; background-image: none;" alt="image" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_6f738213-3f5e-419f-9ceb-fe36a63f4da6.png" /></p> <p>As you can see, there is almost another classe implementing IGeoShape. It is the Geocircle. This class is used to describe a circular area, made of a center and a radius around it. The use of this class is related to the Geofencing, that is the interception of events related to a geographic area. (I'll cover this argument later). </p> <p>Together with the Point property, the Geocoordinate class got another two properties. The SatelliteData is the central point when you need to determine the accuracy of the satellite information. It's properties are able to describe the precision on the basis of the position of satellites in the sky. The argument is pretty complex but, to oversimplify, this parameter can figure if you are getting information from satellites that cover only a little part of the sky (less precise) or well distributed and effective. Finally the PositionSource property lets you know how the position has been detected. In Windows 8 the position can be calculated with many sources, Cellular cells, Satellites, Wi-fi and IP address. All these have different precision and it is important to know what is the source of your measurement. </p> <h3>Getting the position</h3> <p>The way you get a position in Windows 8.1 has not changed, but I'll include an example for the sake of completeness. The main handle for the reading of the location is in the Geolocator class. </p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> Button_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Geolocator locator = <span style="color: #0000ff;">new</span> Geolocator();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> locator.DesiredAccuracy = PositionAccuracy.High;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> var location = await locator.GetGeopositionAsync().AsTask();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">this</span>.DisplayInfo(location);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--></div> </div> <p>Once you create an instance of the type, you can first of all determine the accuracy you want, setting the DesiredAccuracy property to Default or High. As a practical result, when you set the value to High the device will try to use always the most reliable source available, that is Satellite. It this is not available because the device does not have a GPS sensor the positioning is calculated to the next accurate source and then so on. On my desktop PC, that does not have a GPS sensor, nor a cellular or wi-fi connection, the value always returns IPAddress that is the less precise source available. Definitely you have never to strictly rely on positioning precision, since it always try to return a value but this may be very inaccurate. Here is the result of the snippet on my tablet.</p> <p><img width="341" height="192" title="Screenshot (1)" style="margin: 0px 15px 0px 0px; border: 0px none currentcolor; display: inline; background-image: none; float: left;" alt="Screenshot (1)" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/Screenshot%20(1)_344a6a2d-103c-45a6-ab4a-abb5c37f4e8c.png" /></p> <p>As you can see the PositionSource is Wi-Fi. This is because I'm in a closed room and the GPS probably is not able to receive accurate information. </p> <p>The number "4326" in the SpatialReferenceId refers to the WGS84 projection system that is the most common spatial reference, used by Bing and Google as an example. This means you can directly use the Latitude and Longitude on a Bing Map without the need of any conversion. </p> <p>The Geolocator allows you to get the position, as a sequence of events, on the basis of a threshold distance between samples. To setup this you can hook up the PositionChanged event and setup the MovementThreshold property to the required amount of meters. Additionally you can also set the ReportInterval property to indicate the minimum time between different samples, so you can slow down the flow of information and preserve battery from being drained.</p> <h3>Slice the world</h3> <p>Getting a position from your device is for sure a great thing if you need to mark static positions on the earth surface, but listen to me who I've worked on geospatial solutions, it is nothing. When you have a device able to track a geographical position and you want to develop a system on top of it, you immediately meet the need to handle the dynamic aspect of geo location and not only the collection of positions. And in a device like this, it may become an hard task to monitor changes of position, while on the go, and check if they match with given point to track some high level object like a vehicle trip or a goods move.</p> <p>Windows 8.1 makes a great step forward in this direction letting you define a so-called "geo-fence", that is a geographical area that is monitored by the device automatically. A Geofence in WinRT is defined as an element that have an "ID", useful to handle multiple locations, and a shape that is an instance of IGeoShape. </p> <p>Given what we previously said, at the moment WinRT only supports circular shapes. a Geopoint is an IGeoShape but it is too small to be handled by a positioning system. It is almost impossible to detect a Geofence as a point source. So the only shape we can reasonably use is the Geocircle. In my experience, the tracking of circular position does not always suffice, expecially if you have to handle close positions. But for many applications circular areas are good. </p> <p>The main point to handle Geofences is the GeofenceMonitor. It is a singleton object, returned by the Current property and is represents the system-wide instance of the monitor. So be careful. This object esposes a Geofences collection that shows only geofences added by the current application/user. You can user this property to append new geofences, but you always have to handle this collection like a persistent item. Infact if you add an element and then you close the app, when you enter agin the element is still there. So, the better is to handle your collection being always care of the IDs you entered and at least clear them when you enter the application or double check before adding that the element does not exists.</p> <p>Let me propose a simple example. In this example I'll use the previous code to detect the current position and add a geofence around it. </p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> Button_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Geolocator locator = <span style="color: #0000ff;">new</span> Geolocator();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> var location = await locator.GetGeopositionAsync().AsTask();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">this</span>.DisplayInfo(location);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> Geofence fence = GeofenceMonitor.Current.Geofences.FirstOrDefault(o => o.Id == <span style="color: #006080;">"here"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">if</span> (fence == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> GeofenceMonitor.Current.Geofences.Add(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">new</span> Geofence(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #006080;">"here"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;">new</span> Geocircle(location.Coordinate.Point.Position, 50.0),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> MonitoredGeofenceStates.Entered,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">false</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> TimeSpan.FromSeconds(10)));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> }</pre> <!--CRLF--></div> </div> <p>So, after the position has been detected, the first operation is to check is a Geofence with id equals to "here" already exist. Only if the instance does not exists a new Geofence is created and added to the collection. The new geofence has a number of properties. Other to the ID and shape </p> <p>So, after the position has been detected, the first operation is to check is a Geofence with id equals to "here" already exist. Only if the instance does not exists a new Geofence is created and added to the collection. The new geofence has a number of properties. Besides to the ID and shape that are intuitive, the other properties are the following:</p> <ul> <li><strong>monitoredStatus </strong>is a flag property that indicate events we need to be nodified. We can use a boolean OR to specify multiple values like Entered | Exited</li> <li><strong>singleUse</strong> let say if the geofence is persistent. Is single use is true, the Geofence is automatically removed after it has been hit by an event.</li> <li><strong>dwellTime </strong>is the threshold value the device should remain into the geofence before an event is raised. In this case 10 seconds.</li> </ul> <p>In the example, when you hit the button, the position is detected and added as a Geofences. After 10 seconds the GeofenceStateChanged event should be raised (stated that we are still in it). And we handle is as follow:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> MainPage_Loaded(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> GeofenceMonitor.Current.GeofenceStateChanged += Current_GeofenceStateChanged;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> Current_GeofenceStateChanged(GeofenceMonitor sender, <span style="color: #0000ff;">object</span> args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> await <span style="color: #0000ff;">this</span>.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> Geofence changed = (from gf <span style="color: #0000ff;">in</span> sender.Geofences</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">where</span> gf.MonitoredStates != MonitoredGeofenceStates.None</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> select gf).FirstOrDefault();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">if</span> (changed != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> txtMessage.Text = <span style="color: #0000ff;">string</span>.Format(<span style="color: #006080;">"The geofence with id '{0}' changed to '{1}'"</span>, changed.Id, changed.MonitoredStates);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--></div> </div> <p>In this code I search for Geofences that are in a status different from "None" and I display a message in a textbox. With more that a single Geofence the code should be much more complex to handle multiple changes. Be sure you can handle more that a single Geofence signaled ad a time, because nothing prevents you to add items that cover the same position.</p> <h3>Workin' on the go...</h3> <p>The Geofences system is really interesting and straightforward to be used. Unfortunately the code I've shown only works while the application is running. And we for sure know that this is not always true in a WinRT system. It is the reason why the geofencing also supports background tasks, ad this will be the argument from the next article in the series.</p> http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-1-What-s-new-in-geolocation.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-1-What-s-new-in-geolocation.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Location-aware-apps-Part-1-What-s-new-in-geolocation.aspx Mon, 21 Oct 2013 13:34:00 GMT Windows 8.1: Exploring new controls (Hub, CommandBar, Flyouts and Pickers) <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-8.1-Exploring-new-controls-Hub-CommandBar-Flyouts-and-Pickers.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Exploring-new-controls-Hub-CommandBar-Flyouts-and-Pickers.aspx" data-count="horizontal" data-text="Windows 8.1: Exploring new controls (Hub, CommandBar, Flyouts and Pickers). #win8dev" data-url="http://slshow.net/19OVxY7">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-8.1-Exploring-new-controls-Hub-CommandBar-Flyouts-and-Pickers.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p style="text-align: justify;">As often happens, the timeframe passed between the release of Windows 8 and the new release numbered 8.1, have brought to the light some things that developers felt missing during the their work. Many of these are simply obvious features left behind just for time issues, others are answers to new needs that could not be imagined in the first release, and others again are some effective behaviors proposed by some successful application. In this release all these paradigms have created a new output, in the form of a number of "Controls" that are now available to developers.  </p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/news/Latest-and-Greatest-in-Windows-8.1-for-Developers.aspx">Free webinar on Oct 23: <strong>Latest & greatest in Windows 8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">On the front of the "time victims" there are new pickers that simplify the input of Date and Time values and some new flyouts to better answer to the needs of the Moder UI requirements. There is then a new CommandBar, made to implement easily the most common layout of an Application Bar, without the headaches coming from its layout. Finally there is also a new Hub control that make easy and widely available the hub paradigm presented by some application in Windows 8. Turn on the lights and let start explore them.</p> <h3 style="text-align: justify;">The missing pickers and flyouts</h3> <p style="text-align: justify;">Every application, also the most simple, has the need of asking input from the user and usually this is a point where errors and difficulties become hard to be handled. The TextBox control, the sole available before Windows 8.1, it is really hard to ask the user to input different datatypes and create a constrained interface to prevent input errors. The date and time values are a really practical example of this problem and from time to time Microsoft and third party companies provided some specific control in every platform. Windows 8.1 make available the new DatePicker and TimePicker controls, not only to avoid input errors, but also to give a uniform usability to Moder UI interfaces. Here is some examples:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DatePicker</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Abbreviated"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #ff0000;">DayFormat</span><span style="color: #0000ff;">="{}{day.integer}"</span> <span style="color: #ff0000;">DayVisible</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">MonthFormat</span><span style="color: #0000ff;">="{}{month.integer}"</span> <span style="color: #ff0000;">MonthVisible</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">YearFormat</span><span style="color: #0000ff;">="{}{year.abbreviated}"</span> <span style="color: #ff0000;">YearVisible</span><span style="color: #0000ff;">="True"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DatePicker</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="With padding zero"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #ff0000;">DayFormat</span><span style="color: #0000ff;">="{}{day.integer(2)}"</span> <span style="color: #ff0000;">DayVisible</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #ff0000;">MonthFormat</span><span style="color: #0000ff;">="{}{month.integer(2)}"</span> <span style="color: #ff0000;">MonthVisible</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #ff0000;">YearFormat</span><span style="color: #0000ff;">="{}{year.full(4)}"</span> <span style="color: #ff0000;">YearVisible</span><span style="color: #0000ff;">="True"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DatePicker</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Custom format"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #ff0000;">DayFormat</span><span style="color: #0000ff;">="{}{dayofweek.abbreviated} - {day.integer(2)}"</span> <span style="color: #ff0000;">DayVisible</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #ff0000;">MonthFormat</span><span style="color: #0000ff;">="{}{month.abbreviated(3)}"</span> <span style="color: #ff0000;">MonthVisible</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #ff0000;">YearFormat</span><span style="color: #0000ff;">="{}{year.abbreviated}"</span> <span style="color: #ff0000;">YearVisible</span><span style="color: #0000ff;">="True"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DatePicker</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Week day only"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #ff0000;">DayFormat</span><span style="color: #0000ff;">="{}{dayofweek.full}"</span> <span style="color: #ff0000;">DayVisible</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #ff0000;">MonthVisible</span><span style="color: #0000ff;">="False"</span> <span style="color: #ff0000;">YearVisible</span><span style="color: #0000ff;">="False"</span> <span style="color: #0000ff;">/>s</span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The previous examples produce the following output. In this screenshot I've included two Cultures (it-IT and en-US) to show how the control automatically handles internazionalization.</p> <p style="text-align: justify;"><img width="640" height="343" title="datepicker" style="margin: 5px 0px 0px; border: 0px none currentcolor; display: inline; background-image: none;" alt="datepicker" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/datepicker_723a4a21-6e76-4409-89fa-b422b6ab9bfe.png" /></p> <p style="text-align: justify;"> </p> <p style="text-align: justify;">With format properties you can choose from a wide set of formats that are good for the finest tastes. You can also exclude one or more parts of the date when you do not need to get a complete date from your user. As for dates you can also use the TimePicker to get a time value:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TimePicker</span> <span style="color: #ff0000;">ClockIdentifier</span><span style="color: #0000ff;">="24HourClock"</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="24 hour clock"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TimePicker</span> <span style="color: #ff0000;">ClockIdentifier</span><span style="color: #0000ff;">="12HourClock"</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="24 hour clock"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This code shows the following result:</p> <p style="text-align: justify;"><img width="303" height="176" title="image" style="margin: 5px 0px 0px; border: 0px none currentcolor; display: inline; background-image: none; float: left;" alt="image" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_82430892-6b0e-4669-96ce-3631bfad78a6.png" /></p> <p style="text-align: justify;">With the ClockIdentifier property you are able to switch between a 12/24 time picker. The output of the controls are a plain DateTime for the DatePicker and a Timespan fo the TimePicker. This let you to simply add the timespan to the date to get a full DateTime including time.</p> <p style="text-align: justify;">The two control present a wide list of values when an item is selected and this let the user to select easily the choosen value also if he is using a finger instead of the mouse pointer. These controls are definitely awesome and well designed.</p> <p style="text-align: justify;">Another trouble with Windows 8, especially in XAML are the flyouts. Flyout is a generic name give to each part of the user interface that "flies" over other control. This includes the generic popups, menu and the settings panel. To solve these troubles, Windows 8.1 include some new Flyout controls targeted to these issues. Every FrameworkElement can get an attached flyout, using the special attached property "FlyoutBase.AttachedFlyout". This lets you position a flyout relatively to the item it is attached to, setting the Placement property to one of foru predefined value. Once a flyout has been attached to an element, you can show it using the FlyoutBase.ShowAttachedFlyout() method. Here is an example:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Ellipse</span> <span style="color: #ff0000;">Tapped</span><span style="color: #0000ff;">="Ellipse_Tapped"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="Blue"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="50"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="50"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FlyoutBase.AttachedFlyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Flyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Ellipse</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="100"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="100"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="Red"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">Ellipse</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Flyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">FlyoutBase.AttachedFlyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Ellipse</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This code adds a flyout to an Ellipse and sets its content to another (much bigger) Ellipse. To open the flyour you have to manually handle the "Tapped" event and call the ShowAttachedFlyout methot passing a reference to the ellipse to which the flyout is attached. </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Ellipse_Tapped(<span style="color: #0000ff;">object</span> sender, TappedRoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This code opens the flyout as expected, positioned on the top of the element. The flyout is a rectangle area with a border. The Button is a special case for flyouts because it have a "Flyout" property and automatically handle the click to open the attached flyout. So in this case you can simply write this in XAML:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <Button Content=<span style="color: #006080;">"Press me!"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <Button.Flyout></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <Flyout Placement=<span style="color: #006080;">"Bottom"</span>></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <TextBox Header=<span style="color: #006080;">"Enter the name"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> </Flyout></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> </Button.Flyout></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> </Button></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The previous code, without any codebehind, shows the flyout on the left side. </p> <p style="text-align: justify;"><img width="209" height="221" title="image" style="margin: 5px 0px 0px; border: 0px none currentcolor; display: inline; background-image: none; float: right;" alt="image" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_a7e9ecb7-fc43-4249-aee2-f208d0ee4032.png" /></p> <p style="text-align: justify;"><img width="170" height="161" title="image" style="margin: 5px 0px 0px; border: 0px none currentcolor; display: inline; background-image: none; float: left;" alt="image" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_baed4569-af95-48bd-9d27-ebcb6ca7618e.png" /></p> <p style="text-align: justify;">The flyout is a simple container where you can put your own element in plain XAML, and it will behave as if it was in the main Visual Tree. So you can handle events, use databinding and resources. If you need to create a flying menu instead, there is a special Flyout control called menù flyout. Inside it you can use a set of menu items and separators to create list of options the user can select.  At the right side an example of this kind of menù. </p> <p style="text-align: justify;">The control is really simple and includes text items, toggle buttons that appear as a tickmark and a special separator item:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">Content</span><span style="color: #0000ff;">="Do you like Windows 8?"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button.Flyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">MenuFlyout</span> <span style="color: #ff0000;">Placement</span><span style="color: #0000ff;">="Top"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ToggleMenuFlyoutItem</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Yes"</span> <span style="color: #ff0000;">IsChecked</span><span style="color: #0000ff;">="True"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ToggleMenuFlyoutItem</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="No"</span> <span style="color: #ff0000;">IsChecked</span><span style="color: #0000ff;">="False"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">MenuFlyoutSeparator</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">MenuFlyoutItem</span><span style="color: #0000ff;">></span>Cancel<span style="color: #0000ff;"></</span><span style="color: #800000;">MenuFlyoutItem</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">MenuFlyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button.Flyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Finally, the SettingsFlyout let you handle the settings panel with few lines of code. Implementing the settings contract was not so simple before Windows 8.1 because you was in charge of creating all the UI for the settings options. In Windows 8.1 you can create a special UserControl called SettingsFlyout and design it aspect as you do with a normal page. After selecting the "New Item" in Visual Studio you can add a SettingsFlyout element and start with its interface in the designer.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SettingsFlyout</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #ff0000;">x:Class</span><span style="color: #0000ff;">="XPG.WinRTBehaviors.AppSettings"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">xmlns:x</span><span style="color: #0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">xmlns:local</span><span style="color: #0000ff;">="using:XPG.WinRTBehaviors"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">xmlns:d</span><span style="color: #0000ff;">="http://schemas.microsoft.com/expression/blend/2008"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #ff0000;">xmlns:mc</span><span style="color: #0000ff;">="http://schemas.openxmlformats.org/markup-compatibility/2006"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #ff0000;">mc:Ignorable</span><span style="color: #0000ff;">="d"</span> <span style="color: #ff0000;">Title</span><span style="color: #0000ff;">="Settings"</span> <span style="color: #ff0000;">d:DesignWidth</span><span style="color: #0000ff;">="346"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Stretch"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Stretch"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ComboBox</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Language"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Stretch"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,0,25"</span> <span style="color: #ff0000;">SelectedIndex</span><span style="color: #0000ff;">="0"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ComboBoxItem</span><span style="color: #0000ff;">></span>Italian<span style="color: #0000ff;"></</span><span style="color: #800000;">ComboBoxItem</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ComboBoxItem</span><span style="color: #0000ff;">></span>English<span style="color: #0000ff;"></</span><span style="color: #800000;">ComboBoxItem</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ComboBox</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">SettingsFlyout</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Then in the page, handling the CommandRequested event for the settings contract you have to provide a command to open your settings flyout. Into the command you create an instance of the flyout you have created and then call the Show method as you do with a popup.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> MainPage_CommandsRequested(Windows.UI.ApplicationSettings.SettingsPane sender, Windows.UI.ApplicationSettings.SettingsPaneCommandsRequestedEventArgs args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Windows.UI.ApplicationSettings.SettingsCommand settingsCommand =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">new</span> Windows.UI.ApplicationSettings.SettingsCommand(1, <span style="color: #006080;">"Settings"</span>, </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> (handler) =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> AppSettings settings = <span style="color: #0000ff;">new</span> AppSettings();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> settings.Show();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> args.Request.ApplicationCommands.Add(settingsCommand);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">It is really easy and straightforward.</p> <h3 style="text-align: justify;">Simplify your AppBar experience: the CommandBar</h3> <p style="text-align: justify;">Setting up an application bar in XAML is an easy task, but most of the times you simply need to place some buttons inside it, and preparing the layout may be annoying. The new CommandBar control is made to avoid the overhead of work you have in these case and to consolidate the Modern UI guidelines that have a strong requirement for the positioning of buttons inside an application bar. The CommandBar appear as a simple container that hosts a number of buttons.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.BottomAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">CommandBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton</span> <span style="color: #ff0000;">Icon</span><span style="color: #0000ff;">="Home"</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Go to home"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton</span> <span style="color: #ff0000;">Icon</span><span style="color: #0000ff;">="Add"</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Add item"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">CommandBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.BottomAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">All the items that are directly inside the CommandBar are considered "primary" buttons. They are hosted on the immediate right of the application bar as the guidelines prescribe. When you need to add buttons to the left side (the contextual items), you have to use the SecondaryButtons property as in the following example.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.BottomAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">CommandBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton</span> <span style="color: #ff0000;">Icon</span><span style="color: #0000ff;">="Home"</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Go to home"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton</span> <span style="color: #ff0000;">Icon</span><span style="color: #0000ff;">="Add"</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Add item"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">CommandBar.SecondaryCommands</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton</span> <span style="color: #ff0000;">Icon</span><span style="color: #0000ff;">="Delete"</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Delete"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton</span> <span style="color: #ff0000;">Icon</span><span style="color: #0000ff;">="MoveToFolder"</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Move"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarSeparator</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarToggleButton</span> <span style="color: #ff0000;">Icon</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">CommandBar.SecondaryCommands</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">CommandBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.BottomAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This configuration shows the following application bar:</p> <p style="text-align: justify;"><img width="700" height="92" title="commandbar" style="margin: 5px auto 0px; border: 0px none currentcolor; float: none; display: block; background-image: none;" alt="commandbar" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/commandbar_908fed87-45f5-41f6-8abb-5a72b9bb84b5.png" /></p> <p style="text-align: justify;">In this command bar you can see the separator and the Bold button is defined as AppBarToggleButton so you can switch it on or off. The Icon property of the buttons can be set with a predefined serie of given values. This helps to keep the look and feel of applications very similar in the glyphs they uses. You can also use your own bitmap of XAML path to define the image in the icon:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton</span> <span style="color: #ff0000;">Label</span><span style="color: #0000ff;">="Icon with bitmap"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBarButton.Icon</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">BitmapIcon</span> <span style="color: #ff0000;">UriSource</span><span style="color: #0000ff;">="ms-appx:///Assets/Icons/mycustomicon.png"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">AppBarButton.Icon</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">AppBarButton</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">To specify a path you can use the PathIcon element. Additionally, with the FontIcon element you can use a glyph from a font, specifying the FontFamily and the code as and exadecimal value.</p> <h3 style="text-align: justify;">Enhance the apps with the Hub control</h3> <p style="text-align: justify;">One of the more requested features in Windows 8, just after the launch, is the Hub constrol that many applications showed since first days. The news application, but also the sports, meteo and travel come with a similar aspect that allows the user to slide between different sections stacked side by side horizontally. In Windows 8.1 the hub contro become real and the following picture shows how it appear.</p> <p style="text-align: justify;"><img width="702" height="266" title="Capture1" style="margin: 5px auto 0px; border: 0px none currentcolor; float: none; display: block; background-image: none;" alt="Capture1" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/___Capture1.png" /></p> <p style="text-align: justify;">In this example I've created with little effort using my pictures in instagram (<a title="http://instagram.com/thesmallgrove" href="http://instagram.com/thesmallgrove">http://instagram.com/thesmallgrove</a>), you see three sections stacked. The first one (white) is the main section, usually reserved to introduce news. In this figure is shows the most recent picture. The second section contains recent shoots and finally another section shows categories. Nothing prevents you to add other sections and they will be showed scrolling horizontally since the screen usually covers only the first sections (in this example the first and part of the second). The code to create this example is slightly simple; first of all add a Hub control:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Hub</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="TheSmallGrove pictures"</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="White"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Hub</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Here I define the main title of the hub. This title is fixed on the screen and the hub scrolls under it. A section is created using a HubSection element inside the Hub control</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">HubSection</span> <span style="color: #ff0000;">MinWidth</span><span style="color: #0000ff;">="1000"</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Sunset in Peschici (Apulia)"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage8.ak.instagram.com/f0a5619826b411e39cc222000a9f38cc_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,20,0,0"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource BodyTextBlockStyle}"</span><span style="color: #0000ff;">><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Taken:"</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="August, 12 2012"</span> <span style="color: #0000ff;">/></</span><span style="color: #800000;">TextBlock</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource BodyTextBlockStyle}"</span><span style="color: #0000ff;">><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Camera:"</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Leica V-Lux 2"</span> <span style="color: #0000ff;">/></</span><span style="color: #800000;">TextBlock</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource BodyTextBlockStyle}"</span><span style="color: #0000ff;">><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Place:"</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Peschici, Apulia (Italy)"</span> <span style="color: #0000ff;">/></</span><span style="color: #800000;">TextBlock</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">HubSection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This snippet shows the very first section. Inside a section you have to use a DataTemplate to fill the content. Then inside the DataTemplate you place the portion of the Visual Tree. Each section has a title itself and you also convert it to an hyperlink using the IsInteractive property. The other sections are stacked into the hub control. Here is the complete code:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Hub</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="TheSmallGrove pictures"</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="White"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">HubSection</span> <span style="color: #ff0000;">MinWidth</span><span style="color: #0000ff;">="1000"</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Sunset in Peschici (Apulia)"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage8.ak.instagram.com/f0a5619826b411e39cc222000a9f38cc_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,20,0,0"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource BodyTextBlockStyle}"</span><span style="color: #0000ff;">><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Taken:"</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="August, 12 2012"</span> <span style="color: #0000ff;">/></</span><span style="color: #800000;">TextBlock</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource BodyTextBlockStyle}"</span><span style="color: #0000ff;">><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Camera:"</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Leica V-Lux 2"</span> <span style="color: #0000ff;">/></</span><span style="color: #800000;">TextBlock</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource BodyTextBlockStyle}"</span><span style="color: #0000ff;">><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Place:"</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/><</span><span style="color: #800000;">Run</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Peschici, Apulia (Italy)"</span> <span style="color: #0000ff;">/></</span><span style="color: #800000;">TextBlock</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">HubSection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">HubSection</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Recent"</span> <span style="color: #ff0000;">IsHeaderInteractive</span><span style="color: #0000ff;">="True"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="Gainsboro"</span> <span style="color: #ff0000;">MinWidth</span><span style="color: #0000ff;">="400"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.RowDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.RowDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage8.ak.instagram.com/f0a5619826b411e39cc222000a9f38cc_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage3.ak.instagram.com/b4d88ab42b5a11e3ab8622000ab5c723_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage1.ak.instagram.com/7e800e48270d11e3bf1c22000aa8008f_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage6.ak.instagram.com/07cad20225d611e3a73522000a1faf50_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage1.ak.instagram.com/1deed2dc24f911e3be6b22000aa80214_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage7.ak.instagram.com/2f7722e8244011e3ab6722000a1fb853_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage7.ak.instagram.com/5c23c6d623c111e39a4b22000a1fb593_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage7.ak.instagram.com/b3e01a62239611e3b6c622000a1f92d1_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage6.ak.instagram.com/bac0f9f6292111e3995e22000ab5a7b8_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage10.ak.instagram.com/ddbd777827cc11e3a9dd22000a9e29a7_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage2.ak.instagram.com/794a6a5230f111e3815722000aaa049c_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage3.ak.instagram.com/b97c03bc2e9211e3aa3022000a9e2931_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage7.ak.instagram.com/c1db47722cce11e3a23c22000a1f9d66_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage7.ak.instagram.com/9dae4d1c228911e3bb0922000a1fbf4a_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="2"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage6.ak.instagram.com/52eedb6021db11e3935222000a1fb825_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="3"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="190"</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="http://distilleryimage8.ak.instagram.com/62bd4818210611e39ff222000aa8009c_7.jpg"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,20,20"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum49" style="color: #606060;"> 49:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">HubSection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum50" style="color: #606060;"> 50:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum51" style="color: #606060;"> 51:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">HubSection</span> <span style="color: #ff0000;">Header</span><span style="color: #0000ff;">="Categories"</span> <span style="color: #ff0000;">Foreground</span><span style="color: #0000ff;">="White"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum52" style="color: #606060;"> 52:</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="#666666"</span> <span style="color: #ff0000;">MinWidth</span><span style="color: #0000ff;">="300"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum53" style="color: #606060;"> 53:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum54" style="color: #606060;"> 54:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum55" style="color: #606060;"> 55:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Still Life"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource TitleTextBlockStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum56" style="color: #606060;"> 56:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Portrait"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource TitleTextBlockStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum57" style="color: #606060;"> 57:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Landscape"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource TitleTextBlockStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum58" style="color: #606060;"> 58:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Famous places"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{ThemeResource TitleTextBlockStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum59" style="color: #606060;"> 59:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum60" style="color: #606060;"> 60:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum61" style="color: #606060;"> 61:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">HubSection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum62" style="color: #606060;"> 62:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum63" style="color: #606060;"> 63:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Hub</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">One interesting thing is that the Hub control implemente the ISemanticZoomInformation interface. This allows you to use the control in the ZoomedIn/ZoomedOut properties of the SemanticZoom control and navigate between different views using the pich gesture.</p> <h3 style="text-align: justify;">Take it under control.</h3> <p style="text-align: justify;">This release seems to strongly enhance the developer experience, solving much of the issues we experienced previously. thes controls I've shown in this article comes together with a number of new features in the existing control set. It is really important that you scan for these changes because much of the times they makes you really fast and productive.</p> http://www.silverlightshow.net/items/Windows-8.1-Exploring-new-controls-Hub-CommandBar-Flyouts-and-Pickers.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Exploring-new-controls-Hub-CommandBar-Flyouts-and-Pickers.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Exploring-new-controls-Hub-CommandBar-Flyouts-and-Pickers.aspx Tue, 15 Oct 2013 14:40:00 GMT Windows 8.1: Behaviors SDK - Part #2 <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-2.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/1bC5l9j" data-text="Reading @aboschin's article: Windows 8.1: Behaviors SDK - Part #2. #win8dev" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-2.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-2.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p style="text-align: justify;">After the last article where I spoken about the use of behaviors in Windows 8.1, it is time now to go deep inside the SDK and try to create our own behaviors. The SDK in Windows 8.1 includes a number of predefined behaviors that out-of-the box cover a number of cases, both with different activations (event driven and data driven) and with a number of actions, from the simplest property change to the manipulation of states and the invocation of commands. Connecting together predefined activation behaviors and actions suffice for most of the problems you may meet during development, but there are cases when only a specifically-tailored logic can solve an hassle. Here is the need of creating some behaviors and actions with our hands.</p> <h3 style="text-align: justify;">Actions or Behaviors?</h3> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/news/Latest-and-Greatest-in-Windows-8.1-for-Developers.aspx">Free webinar on Oct 23: <strong>Latest & greatest in Windows 8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">Once you added the references to the behavior SDK, as I shown in the previous number, you have in your hand not only the existing behaviors but also the toolset you need to create your own. The first is to correctly decide how to choose between behaviors and actions. </p> <p style="text-align: justify;">For a correct choice you have to carefully watch at the problem you have to solve. It is not true that behaviors are made only to activate actions, but it is for sure that actions need a behavior to be applied to an element. Infact, since an action strongly requires that someone else activate its logic, the behaviors are directly connected to an element in the Visual Tree and can both attach event and properties and manipulate them. </p> <p style="text-align: justify;">Generally speaking, you should fall to create Actions when the predefined trigger behaviors suffice to activate your logic. So if you can rely on EventTriggerBehavior or on DataTriggerBehavior you can for sure implement and action and leave out of your mind the activation problem.</p> <p style="text-align: justify;">Differently, if you can go with predefined actions but you are unable to start them with one of the predefined triggers then you have to implement a behavior. This let you too hook up the control and then requires to scan actions and execute them.</p> <p style="text-align: justify;">Finally, if you need complex logic that require to hook up multiple events and properties, both the get/set states and information, then the better is to use a behavior and forget actions. </p> <h3 style="text-align: justify;">Create a simple trigger behavior</h3> <p style="text-align: justify;">Let say we need to implement a new activation trigger. It's hard to figure out what you may need that does not fall into handling events and data changes. The only thing I have imagined is to handle the time dimension. So, for this example I'll show how to create a behavior able to trigger actions on the basis of a periodic timeout, a sort of snooze alarm, that will awake something in our user interface. </p> <p style="text-align: justify;">Implementing a behavior in Windows 8.1 do not mean extending an abstract class, like it was in Silverlight, but it requires you to implement a simple interface. This interface called IBehavior - it resides under the Microsoft.Xaml.Interactivity namespace - is a lightweight version of the Behavior<T> class that we used in Silverlight, but it has a drawback. It directly applies to every DependencyObject without any distinction, so we cannot apply limitations on the basis of the target type. this makes programming slightly more difficult because you have to double check that the associated object can be manipulated by your logic. For this purpose we can create our own abstraction:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">abstract</span> <span style="color: #0000ff;">class</span> Behavior<T> : DependencyObject, IBehavior</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">where</span> T : DependencyObject</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">public</span> T AssociatedObject { get; <span style="color: #0000ff;">private</span> set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">abstract</span> <span style="color: #0000ff;">void</span> OnAttached();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">abstract</span> <span style="color: #0000ff;">void</span> OnDetached();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> DependencyObject IBehavior.AssociatedObject</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> get { <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">this</span>.AssociatedObject; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">void</span> IBehavior.Attach(DependencyObject associatedObject)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">if</span> (associatedObject != <span style="color: #0000ff;">null</span> &&</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> !associatedObject.GetType().GetTypeInfo().IsSubclassOf(<span style="color: #0000ff;">typeof</span>(T)))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> Exception(<span style="color: #006080;">"Invalid target type"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;">this</span>.AssociatedObject = associatedObject <span style="color: #0000ff;">as</span> T;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;">this</span>.OnAttached();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">void</span> IBehavior.Detach()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;">this</span>.OnDetached();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> <span style="color: #0000ff;">this</span>.AssociatedObject = <span style="color: #0000ff;">null</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The class explicitely implements the IBehavior interface, so I'm able to override the AssociatedObject property and publish it to inherited classes. This property is strongly typed using the generic type T and this make the work much more easy. In the Attach methos then I check that the incoming object is compatible with T and in case I throw and exception. </p> <p style="text-align: justify;">To create a trigger we need to collect some actions and then raise the execution when it is required. It is another point we can handle with a base class. I will call it Trigger<T>:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> [ContentProperty(Name = <span style="color: #006080;">"Actions"</span>)]</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">abstract</span> <span style="color: #0000ff;">class</span> Trigger<T> : Behavior<T></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">where</span> T : DependencyObject</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">public</span> Trigger()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">this</span>.Actions = <span style="color: #0000ff;">new</span> ActionCollection();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">public</span> ActionCollection Actions</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> get;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">private</span> set;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Execute(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> parameter)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">foreach</span> (IAction item <span style="color: #0000ff;">in</span> <span style="color: #0000ff;">this</span>.Actions.OfType<IAction>())</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> item.Execute(sender, parameter);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The Trigger class exposes an Actions property. This is used to host child actions. Blend will recognize it and the designer should show the hierarchy correctly. The "ContentProperty" attribute on the class is used to allow direct content in the XAML to be mapped to this property. Finally the "Execute method crawls the child actions and calls tha Execute method of the IAction interface. Now the implementation is much more easy:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> TimeTrigger : Trigger<Shape></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> DateTime PreviousTime { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">private</span> Timer Timer { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Interval</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> get; set;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnAttached()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">this</span>.PreviousTime = DateTime.Now;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">this</span>.Timer = <span style="color: #0000ff;">new</span> Timer(OnTick, <span style="color: #0000ff;">null</span>, 0, 1000);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnDetached()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #008000;">// does nothing...</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> OnTick(<span style="color: #0000ff;">object</span> state)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> DateTime now = DateTime.Now;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">if</span> (now.Subtract(<span style="color: #0000ff;">this</span>.PreviousTime).TotalSeconds >= <span style="color: #0000ff;">this</span>.Interval)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> <span style="color: #0000ff;">this</span>.PreviousTime = now;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> <span style="color: #cc6633;">#pragma</span> warning disable 4014</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> <span style="color: #0000ff;">this</span>.AssociatedObject.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> <span style="color: #0000ff;">base</span>.Execute(<span style="color: #0000ff;">this</span>.AssociatedObject, now);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> <span style="color: #cc6633;">#pragma</span> warning restore 4014</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The TimeTrigger class uses a Timer to raise an event every second. Then it check the time passed after the previous event and when it is greater than the specified interval it raises the actions. Take note that the "#pragma disable/restore" is used to prevent a warning that is raised because the RunAsync method of the dispatcher is asynchronous and we do not use the "async/await" pattern. It is not so important to await the execution here so I simply call it and forget. The call is marshaled to the UI thread just because the Timer represents a different thread and we need to avoid cross threading issues.</p> <p style="text-align: justify;">To test this trigger you can use a ChangePropertyAction ann you should see the change happening after the interval is passed. Blend should show the new behavior in its assets panel, together with core behaviors.</p> <h3 style="text-align: justify;">Camera... Action!</h3> <p style="text-align: justify;">The implementation of a trigger behavior is slightly complex if you start from the IBehavior interface, but once you created your infrastructure classes it becomes rally easy. For actions instead, there is not a good reaso to bouild some infrastructure over the IAction interface. The interface has a single method and it goes directly to the implementation. </p> <p style="text-align: justify;">Let see a simple action. When our time trigger raises the action I would like to randomly change the color of the shape. So I create a GenerateRandomColor action:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> GenerateRandomColor : DependencyObject, IAction</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> Random generator = <span style="color: #0000ff;">new</span> Random(DateTime.Now.Millisecond);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">private</span> List<Color> colors = <span style="color: #0000ff;">new</span> List<Color>();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">public</span> GenerateRandomColor()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Type type = <span style="color: #0000ff;">typeof</span>(Colors);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">foreach</span> (var property <span style="color: #0000ff;">in</span> type.GetRuntimeProperties())</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">if</span> (property.PropertyType == <span style="color: #0000ff;">typeof</span>(Color))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> colors.Add((Color)property.GetValue(<span style="color: #0000ff;">null</span>));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> DependencyProperty PropertyNameProperty =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> DependencyProperty.Register(<span style="color: #006080;">"PropertyName"</span>, <span style="color: #0000ff;">typeof</span>(<span style="color: #0000ff;">string</span>), <span style="color: #0000ff;">typeof</span>(GenerateRandomColor), <span style="color: #0000ff;">new</span> PropertyMetadata(<span style="color: #0000ff;">null</span>));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> PropertyName</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> get { <span style="color: #0000ff;">return</span> (<span style="color: #0000ff;">string</span>)GetValue(PropertyNameProperty); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> set { SetValue(PropertyNameProperty, <span style="color: #0000ff;">value</span>); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">object</span> Execute(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> parameter)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> FrameworkElement element = sender <span style="color: #0000ff;">as</span> FrameworkElement;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> <span style="color: #0000ff;">if</span> (element != <span style="color: #0000ff;">null</span> & !<span style="color: #0000ff;">string</span>.IsNullOrEmpty(<span style="color: #0000ff;">this</span>.PropertyName))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> PropertyInfo property = element.GetType().GetRuntimeProperty(<span style="color: #0000ff;">this</span>.PropertyName);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> <span style="color: #0000ff;">if</span> (property != <span style="color: #0000ff;">null</span> && property.PropertyType == <span style="color: #0000ff;">typeof</span>(Brush))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> property.SetValue(element, <span style="color: #0000ff;">this</span>.GetRandom());</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span> <span style="color: #0000ff;">private</span> Brush GetRandom()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span> <span style="color: #0000ff;">int</span> random = generator.Next(0, 1000) % <span style="color: #0000ff;">this</span>.colors.Count;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> SolidColorBrush(<span style="color: #0000ff;">this</span>.colors[random]);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum49" style="color: #606060;"> 49:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Into the Action, in the ctor I scan the Colors class to create a palette. This copies the default system colors to a list to have a cout of them an a index to retrieve the instance. When the action is called, a number is generated in the range from 0 and the max number of colors in the array. The color is picked and it is assigned to the target property. The code uses some reflection to dynamically pick up the target property and made the assignment. Nothing else. </p> <p style="text-align: justify;">Now that the action is ready we can use Blend to configure the behavior. Pay attention that you will be required to manually enter the property name. There is not a way to instruct Blend to use the property selector as for ChangePropertyAction. The finally XAML markup should be like this:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="White"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="100"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="100"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Interactivity:Interaction.Behaviors</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">code:TimeTrigger</span> <span style="color: #ff0000;">Interval</span><span style="color: #0000ff;">="15"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">code:GenerateRandomColor</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Fill"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">code:TimeTrigger</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Interactivity:Interaction.Behaviors</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Rectangle</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">When you run the example, after 15 seconds you will have to see the rectangle change its color randomly. Then again after another 15 seconds and so on. </p> <h3 style="text-align: justify;">Why and when?</h3> <p style="text-align: justify;">Behavior are a wonderful tool in your hands but, as it always happens, you have to carefully evaluate when and why to use them. It's definitely wrong to use extensively behaviors, expecially if you do not need to reuse it. Behaviors are tailored to take a recurrent piece of logic, applied to an user interface, and make it reusable across different pages and often across different apps. Another good reason to use behaviors may be to remove parts of codebehind, that may translates values of the view model into operations that cannot be handled by VisualStateManager or Converters. This lead to simplify the application, and mostly to isolate a specific locic that usually become again highly reusable. So please pay always attention on how you use the toolset because a wrong use may be worst of the problem you are trying to address.</p> http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-2.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-2.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-2.aspx Mon, 07 Oct 2013 12:22:00 GMT Windows 8.1: Behaviors SDK - Part #1 <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx" data-count="horizontal" data-text="Reading @aboschin's article: Windows 8.1: Behaviors SDK - Part #1. #win8dev" data-url="http://slshow.net/16NFnxU">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p style="text-align: justify;">Together with Silverlight 3.0 RTM, hidden inside the release of Blend 3.0 in later 2009, Microsoft released an interesting feature that in the projects had to support Sketckflow users. These small pieces of codes, at the first sight appeared as a "draggable" logic, made to increase the designers productivity by adding specific behaviors to objects, directly from the design surface. The "behaviors", this is the name given to these new elements, were part of the Blend 3.0 SDK as a separate download and this contributed to them success. Infact, the behaviors have gained an important part into the scene, just because they are not only part of Blend, but also and expecially because they was easy to be created by developers that started to take advantage of them immediately.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/news/Latest-and-Greatest-in-Windows-8.1-for-Developers.aspx">Free webinar on Oct 23: <strong>Latest & greatest in Windows 8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Understand-the-projects.aspx">Andrea's article series: Windows Store apps with XAML and HTML</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">After the first release, behavior continued to live not only in Silverlight, but also in Windows Phone and they have been always appreciated for the capability of abstracting an user interface behavior, including it into a small reusable class. This is really important, not only to grant designers to add these behaviors without the need of knowing how to write code, but also, because they are able to strip away some UI logic that previously required programming the codebehind of pages and controls. So they are an important piece into the daily fight to the mixing of business logic and interface logic. </p> <h3 style="text-align: justify;">Windows 8.1 and the Behaviors SDK</h3> <p style="text-align: justify;">This said, it is very understandable the disappointment that comes when people discovered that behaviors have been pulled out of XAML for Windows 8. This disappointment was really justified because behaviors have been a filler for missing aspects in Silverlight and, when they have been removed, nothing have been put in place to fill these same gaps. One of the most common usage of behaviors was the invocation of ICommand instances in ViewModel, to attach a command to almost every available event in the View. With their departure this problem returned to the writing into codebehind.</p> <p style="text-align: justify;">Luckily, the team behind XAML for Windows 8 listened carefully to people and in the latest release of Windows 8.1 they added the support for a subset of Behaviors, that is still reduced if compared with Silverlight and Windows Phone but they suffice to resolve the most of the problems they originally covered. </p> <p style="text-align: justify;"><img width="559" height="235" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_a82a2f2c-3619-4d8a-8294-6491a6dc6c1d.png" alt="image" style="margin: 5px 0px 0px 15px; display: inline; background-image: none; float: right; border-width: 0px; border-style: solid;" title="image" />Behavior SDK, to confirm a tradition, is not directly part of the core libraries, but it comes as a separate set of assemblies, shipped together with Visual Studio 2013. To add behaviors to your application, the first stop is the "references dialog", where you can include the "Behavior SDK (XAML)" item into the "Windows -> Extensions" tab. </p> <p style="text-align: justify;">After having added this reference, the behaviors become available and the first place where they appear is its natural location: Blend. To experiment with behaviors, just create a simple blank application and the open it in Blend for Visual Studio 2013. Behaviors appears (again) in the "assets" tab under the omonimous section. There is a small set of predefined behaviors in place and we can directly start to familiarize with them. </p> <p style="text-align: justify;"><img width="263" height="205" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_1b6224d5-4b28-4e95-80bb-711259487874.png" alt="image" style="margin: 5px 10px 0px 0px; display: inline; background-image: none; float: left; border-width: 0px; border-style: solid;" title="image" />Before to start, it is important to understand some subtle differences, you may have noticed in the figure on the left side.</p> <p style="text-align: justify;">There are two type of items in this list. The ones that have a small arrow as the icon and the ones that have a gear. The first are called Actions and the second are Behaviors. The differences come from the fact that Actions needs a behavior to run while behaviors can be directly attached to objects and they are able to attach its properties and events. Leaving on the side the "IncrementalUpdateBehavior" - it is specially tailored to add incremental loading to ItemsControl -there are two remaining behaviors: EventTriggerBehavior and DataTriggerBehavior.</p> <h3 style="text-align: justify;">An easy example: EventTriggerBehavior</h3> <p style="text-align: justify;">As the name suggests, EventTriggerBehavior is able to attach a specific event of the object which it is attached to, and when the event is raised it executes one or more actions. Let me do an example using a simple Action called ChangePropertyAction. Drag inside the canvas of the page two rectangles of 100x100 of size. Then, dragging it from the Assets tab, add an instance of this action to one of the rectangles. </p> <p style="text-align: justify;"><img width="237" height="194" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/image_f3ee3321-4a03-453c-9aa7-570ad6dd4cf0.png" alt="image" style="margin: 5px 0px 0px 15px; display: inline; background-image: none; float: right; border-width: 0px; border-style: solid;" title="image" /></p> <p style="text-align: justify;">The resulting structure in the Project is reported on the right side. Blend automatically added a "EventTriggerBehavior" and then it added the ChangePropertyAction to it. Now we have to configure the behavior. After having selected it in the structure, in the properties tab we are able to choose an event from a dropdown list. These are the events published by the "Rectangle". For this example simply choose the PointerPressed event. The "Source object" property should be set to the rectangle where the behavior has been attached. </p> <p style="text-align: justify;">Now its time to select the inner action. This action has a "Target object" property that is initially set to the same object to which the behavior has been applied. Dragging the circle on the right side over the target object we have to select the secondary rectangle as the target. This way the dropdown list will show the name of all the Dependency Properties of the target rectangle. Selecting a property we are presented with a panel that let us select the desired value. As an example if you choose the "Background" property the designer presents the color selector. Select your preferred color and then run the example.</p> <p style="text-align: justify;">Please take note that the codebehind of the application is still empty a no other code have been added. Running the exaample we should see the secondary rectangle changing its fill color when the primary is clicked. As an experiment you can add some other ChangePropertyAction instances and connect it with other properties of the same target or of others.</p> <h3 style="text-align: justify;">Introducing the DataTriggerBehavior</h3> <p style="text-align: justify;">DataTriggerBehavior instead is able to detect the change of a property, basing it works on the INotifyPropertyChanged interface. Using this trigger you can monitor a property and have the actions called when a specific value has been set. To make an example we should try to add a ViewModel to the page. This ViewModel should implment INotifyPropertyChanged and it have a "Now" property that contains the most recent time. Here is the code:</p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> MainPageViewModel : INotifyPropertyChanged</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">event</span> PropertyChangedEventHandler PropertyChanged;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">public</span> CoreDispatcher Dispatcher { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">public</span> Timer Timer { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">private</span> DateTime now;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">public</span> DateTime Now </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> get { <span style="color: #0000ff;">return</span> now; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> set</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">if</span> (now != <span style="color: #0000ff;">value</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> now = <span style="color: #0000ff;">value</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">this</span>.RaisePropertyChanged(<span style="color: #006080;">"Now"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> RaisePropertyChanged(<span style="color: #0000ff;">string</span> propertyName)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> PropertyChangedEventHandler handler = PropertyChanged;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">if</span> (handler != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> handler(<span style="color: #0000ff;">this</span>, <span style="color: #0000ff;">new</span> PropertyChangedEventArgs(propertyName));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> <span style="color: #0000ff;">public</span> MainPageViewModel()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> <span style="color: #0000ff;">this</span>.Dispatcher = Window.Current.Dispatcher;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> <span style="color: #0000ff;">this</span>.Timer = <span style="color: #0000ff;">new</span> Timer(Tick, <span style="color: #0000ff;">null</span>, TimeSpan.Zero, TimeSpan.FromSeconds(1));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> Tick(<span style="color: #0000ff;">object</span> state)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> await <span style="color: #0000ff;">this</span>.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => <span style="color: #0000ff;">this</span>.Now = DateTime.Now);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> }</pre> <!--CRLF--></div> </div> <p style="text-align: justify;">The example ViewModel also have a Timer instance that automatically changes the value of the "Now" property every half a second. This result to a notification to the View that we may connect with a DataTriggerBehavior. Let see the XAML code; now it is time to go back to Visual Studio 2013 to have a look to the code, but remember that you can accomplish the same using only the Blend's designer. </p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">xmlns:x</span><span style="color: #0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">xmlns:local</span><span style="color: #0000ff;">="using:XPG.WinRTBehaviors"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">xmlns:d</span><span style="color: #0000ff;">="http://schemas.microsoft.com/expression/blend/2008"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">xmlns:mc</span><span style="color: #0000ff;">="http://schemas.openxmlformats.org/markup-compatibility/2006"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #ff0000;">xmlns:Interactivity</span><span style="color: #0000ff;">="using:Microsoft.Xaml.Interactivity"</span> <span style="color: #ff0000;">xmlns:Core</span><span style="color: #0000ff;">="using:Microsoft.Xaml.Interactions.Core"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #ff0000;">xmlns:Media</span><span style="color: #0000ff;">="using:Microsoft.Xaml.Interactions.Media"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #ff0000;">x:Class</span><span style="color: #0000ff;">="XPG.WinRTBehaviors.MainPage"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="page"</span> <span style="color: #ff0000;">mc:Ignorable</span><span style="color: #0000ff;">="d"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.DataContext</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">local:MainPageViewModel</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.DataContext</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="{ThemeResource ApplicationPageBackgroundThemeBrush}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Interactivity:Interaction.Behaviors</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThanOrEqual"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="0"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r9}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThanOrEqual"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="6"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r8}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThanOrEqual"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="12"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r7}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThanOrEqual"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="18"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r6}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThanOrEqual"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="24"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r5}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum49" style="color: #606060;"> 49:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum50" style="color: #606060;"> 50:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum51" style="color: #606060;"> 51:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum52" style="color: #606060;"> 52:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum53" style="color: #606060;"> 53:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThanOrEqual"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="30"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum54" style="color: #606060;"> 54:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r4}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum55" style="color: #606060;"> 55:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum56" style="color: #606060;"> 56:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum57" style="color: #606060;"> 57:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum58" style="color: #606060;"> 58:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum59" style="color: #606060;"> 59:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum60" style="color: #606060;"> 60:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThanOrEqual"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="36"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum61" style="color: #606060;"> 61:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r3}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum62" style="color: #606060;"> 62:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum63" style="color: #606060;"> 63:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum64" style="color: #606060;"> 64:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum65" style="color: #606060;"> 65:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum66" style="color: #606060;"> 66:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum67" style="color: #606060;"> 67:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThan"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="42"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum68" style="color: #606060;"> 68:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r2}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum69" style="color: #606060;"> 69:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum70" style="color: #606060;"> 70:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum71" style="color: #606060;"> 71:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum72" style="color: #606060;"> 72:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum73" style="color: #606060;"> 73:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum74" style="color: #606060;"> 74:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:DataTriggerBehavior</span> <span style="color: #ff0000;">Binding</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">ComparisonCondition</span><span style="color: #0000ff;">="GreaterThan"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="48"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum75" style="color: #606060;"> 75:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction</span> <span style="color: #ff0000;">TargetObject</span><span style="color: #0000ff;">="{Binding ElementName=r1}"</span> <span style="color: #ff0000;">PropertyName</span><span style="color: #0000ff;">="Visibility"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum76" style="color: #606060;"> 76:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum77" style="color: #606060;"> 77:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span>Visible<span style="color: #0000ff;"></</span><span style="color: #800000;">Visibility</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum78" style="color: #606060;"> 78:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction.Value</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum79" style="color: #606060;"> 79:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:ChangePropertyAction</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum80" style="color: #606060;"> 80:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Core:DataTriggerBehavior</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum81" style="color: #606060;"> 81:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Interactivity:Interaction.Behaviors</span><span style="color: #0000ff;">></span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum82" style="color: #606060;"> 82:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum83" style="color: #606060;"> 83:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum84" style="color: #606060;"> 84:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum85" style="color: #606060;"> 85:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum86" style="color: #606060;"> 86:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Orientation</span><span style="color: #0000ff;">="Vertical"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">UseLayoutRounding</span><span style="color: #0000ff;">="True"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum87" style="color: #606060;"> 87:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r1"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="#FF007D91"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum88" style="color: #606060;"> 88:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r2"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="Blue"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum89" style="color: #606060;"> 89:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r3"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="#FF6800FF"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum90" style="color: #606060;"> 90:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r4"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="#FFE800FF"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum91" style="color: #606060;"> 91:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r5"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="Red"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum92" style="color: #606060;"> 92:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r6"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="#FFFF4600"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum93" style="color: #606060;"> 93:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r7"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="#FFFF8B00"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum94" style="color: #606060;"> 94:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r8"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="#FFF3FF00"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum95" style="color: #606060;"> 95:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="r9"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="White"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="Black"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="25"</span> <span style="color: #ff0000;">RenderTransformOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,5,0,0"</span> <span style="color: #ff0000;">Visibility</span><span style="color: #0000ff;">="Collapsed"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum96" style="color: #606060;"> 96:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum97" style="color: #606060;"> 97:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">TextWrapping</span><span style="color: #0000ff;">="Wrap"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="{Binding Now.Second, Mode=OneWay}"</span> <span style="color: #ff0000;">FontSize</span><span style="color: #0000ff;">="96"</span> <span style="color: #ff0000;">FontFamily</span><span style="color: #0000ff;">="Consolas"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum98" style="color: #606060;"> 98:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum99" style="color: #606060;"> 99:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p style="text-align: justify;">In this XAML we have 9 small rects stacked and each rectangle is connected with a DataTriggerBehavior that checks the "Second" value of the DateTime in "Now". Each trigger is set to launch a ChangePropertyAction at different values (0, 6, 12, 18, 24, etc...) with a condition od "GreateThanOrEquals". The property to change is "Visibility". When you run the example you have the Second property continuously increasing and the triggers are set at increasing values. This makes the rects appear one every 6 seconds in a sequence. The strange thing is that once the trigger is set, it is not reset when the value fall back to less then the threshold. This is because the DataTriggerBehavior changes always the property from Collapsed to Visible. It does not have any knowledge of the inverse operation. To make the opposite operation you have to attach another series of triggers with the LessThan clause switching a ChangePropertyAction that set again the Collapsed value.</p> <h3 style="text-align: justify;">About Other Actions</h3> <p style="text-align: justify;">With this example I've only scratched the surface. Side by side with ChangePropertyAction there are a number of other actions ready out of the box. Here is a brief list:</p> <ul> <li> <div style="text-align: justify;"><strong>CallMethodAction</strong>: the action will call a method on a target object. If used with EventTriggerBehavior it is like attaching an event handler in code.</div> </li> <li> <div style="text-align: justify;"><strong>ControlStoryBoardAction</strong>: it is able to control a storyboard, invoking Play, Stop and other actions. </div> </li> <li> <div style="text-align: justify;"><strong>GoToStateAction</strong>: It is useful to change a state of the VisualStateManager. </div> </li> <li> <div style="text-align: justify;"><strong>InvokeCommandAction</strong>: This action is useful for MVVM programming since it is capable of invoking a command on the ViewModel. USed with the EventTriggerBehavior lets you attach commands to each event of every control.</div> </li> <li> <div style="text-align: justify;"><strong>NavigateToPage</strong>: This is useful to trigger navigation to another page in your project</div> </li> <li> <div style="text-align: justify;"><strong>PlaySoundAction</strong>: Intuitively this is for plating a sound when a condition is hit.</div> </li> </ul> <p style="text-align: justify;">A combination of one or more types from this list can generate complex logic, without impacting the codebehind or the viewmodel. This often becomes too much complex, requiring long design sessions, but be aware that you can also write your own behaviors and triggers to include logic that are not available with predefined actions or to reduce the complexity. I'll be back on the building of custom behavior and action in the next article.</p> http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx#comments http://www.silverlightshow.net/items/Windows-8.1-Behaviors-SDK-Part-1.aspx Mon, 30 Sep 2013 11:37:00 GMT Windows Store apps with XAML and HTML: Organize your UI layer in HTML <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Organize-your-UI-layer-in-HTML.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Organize-your-UI-layer-in-HTML.aspx" data-count="horizontal" data-text="#WindowsStore apps with #XAML & #HTML - Organize your UI layer in HTML. #win8dev" data-url="http://slshow.net/1ffrjjU">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Organize-your-UI-layer-in-HTML.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/OrganizeUIWithHTML.zip">Download the source code for this article</a></strong> </div> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/news/Latest-and-Greatest-in-Windows-8.1-for-Developers.aspx">Free webinar on Oct 23: <strong>Latest & greatest in Windows 8.1 for devs</strong>!</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Advanced-MVVM-concepts-using-Contoso-Cookbook-An-analysis-of-a-complete-MVVM-application-Part-1.aspx">Gill Cleeren's article series: Advanced MVVM concepts using Contoso Cookbook</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p>In my last article I showed a simple example about the organization of the UI layer using Model View ViewModel in XAML. There is not any doubt that this pattern is a great help to make the application more maintainable, thanks to the effective separation between logic and views. MVVM is born with XAML, but after you embraced its power, it is hard to give up and return to the previous ways to develop applications. So my question is: "is it possible to apply the same pattern outside of XAML, also in an HTML5 app?" The first and evident obstacle to this achievement is the complete lack of databinding in Javascript and additionally the lack of some tools, like observables types, that directly feed the pattern.</p> <h3>Meet Knockout JS</h3> <p>Luckily someone has my same feel and he created a javascript framework that enables MVVM in web pages, to support that so called Single Page Applications (something you have to try if you are a web developer). Knockout JS is a very impressive and powerful toolset that adds the missing tools to Javascript. It is based on the concept of observables object and on a set of bindings that may be added to a plain html page to simulate the databinding you are use to see in XAML. As I said Knockout JS (<a href="http://knockoutjs.com/)">http://knockoutjs.com/)</a> is for html pages but it is enough smart and flexible to be used inside a Windows Store app, without great troubles. </p> <p>At the very basis of the library there are observables. These are objects that are able to encapsulate a plain variable and make it able to notify its status changes. After you included Knockout JS in a page, you can make a variable (or an array) observable using something like this:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">// simple types</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">this</span>.name = ko.observable(<span style="color: #006080;">"Andrea"</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #008000;">// arrays</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">this</span>.names = ko.observableArray([<span style="color: #006080;">"Andrea"</span>, <span style="color: #006080;">"Gaia"</span>, <span style="color: #006080;">"Daniela"</span>]);</pre> <!--CRLF--></div> </div> <p>After you exposed a property like these in a Javascript class (the viewmodel), you can connect it to the view using a simple "data-bind" attribute. It appears like this: </p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">span</span> <span style="color: #ff0000;">data-bind</span><span style="color: #0000ff;">="text: name"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--></div> </div> <p>Then, the last thing is to connect the View with ViewModel. Usually this happens in the document's ready event. This starts Knockout binding and make the magic happen. Usually people that uses jQuery write something like this:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> $(<span style="color: #0000ff;">function</span>(ev)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> ko.applyBindings(<span style="color: #0000ff;">new</span> MyViewModel());</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> });</pre> <!--CRLF--></div> </div> <p>So now you can update your property and have it updated into the view automatically. The trick is to call a method with the same name of the property instead of assigning the value to the property itself: </p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">// for simple properties</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">this</span>.name(<span style="color: #006080;">"Gaia"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #008000;">// for arrays (add an element)</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">this</span>.names.push(<span style="color: #006080;">"Vanessa"</span>);</pre> <!--CRLF--></div> </div> <p>Observable arrays can be manipulated with a set of methods that is similar to the ones you are use to see in a plain javascript array.</p> <h3>Apply Knockout JS to Windows Store apps</h3> <p>What you seen in the previous section, also applies to a Windows Store app in HTML. Knockout JS works like a breeze and you only have to take care of where to activate the bindings. Usually the best place is the ready event into the page's codebehind. </p> <p>But we should make a step behind: let say we want to replicate the example of the previous article. You firstly create the NamePage.html and this automatically creates the NamePage.js. Then you reference this page in the default.html as usual and then you need to add references to Knockout JS. The default.html page is the best place to put the script tags because it is the container for each other page:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><!</span><span style="color: #800000;">DOCTYPE</span> <span style="color: #ff0000;">html</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">meta</span> <span style="color: #ff0000;">charset</span><span style="color: #0000ff;">="utf-8"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></span>Elite.HTML5vsXAML.Html<span style="color: #0000ff;"></</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #008000;"><!-- WinJS references --></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">link</span> <span style="color: #ff0000;">href</span><span style="color: #0000ff;">="http://Microsoft.WinJS.1.0/css/ui-dark.css"</span> <span style="color: #ff0000;">rel</span><span style="color: #0000ff;">="stylesheet"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">script</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">="http://Microsoft.WinJS.1.0/js/base.js"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">script</span><span style="color: #0000ff;">></span><!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <script src=<span style="color: #006080;">"http://Microsoft.WinJS.1.0/js/ui.js"</span>></script></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <!-- Knockout references --></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="background-color: #ffff00; color: #ff0000;"><strong><script src=<span style="color: #006080;">"/js/knockout-2.3.0.js"</span>></script></strong></span></pre> <!--CRLF--><!--CRLF--><!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <strong><span style="background-color: #ffff00; color: #ff0000;"><script src=<span style="color: #006080;">"/js/knockout-winjs.js"</span>></script></span></strong></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <!-- Elite.HTML5vsXAML.Html references --></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <link href=<span style="color: #006080;">"/css/default.css"</span> rel=<span style="color: #006080;">"stylesheet"</span> /></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <script src=<span style="color: #006080;">"/js/default.js"</span>></script></pre> <!--CRLF--><!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <script src=<span style="color: #006080;">"/js/navigator.js"</span>><span style="color: #0000ff;"></</span><span style="color: #800000;">script</span><span style="color: #0000ff;">></span></pre> <!--CRLF--><span style="color: #0000ff;"> </span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="contenthost"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="Application.PageControlNavigator"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{home: '/views/NamePage/NamePage.html'}"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>Then you go to the NamePage.js file and into the ready event you activate the binding this way:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">/// <reference path="../../js/knockout-2.3.0.js" /></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #008000;">/// <reference path="../../js/knockout-winjs.js" /></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> (<span style="color: #0000ff;">function</span> ()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #006080;">"use strict"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> WinJS.UI.Pages.define(<span style="color: #006080;">"/views/NamePage/NamePage.html"</span>, {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> ready: <span style="color: #0000ff;">function</span> (element, options)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> ko.applyBindings(<span style="color: #0000ff;">new</span> NamePageViewModel(WinJS.Navigation.state));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> })();</pre> <!--CRLF--></div> </div> <p>The NamePageViewModel class is the ViewModel assigned to this page. It is created as a plain Javascript class and exposes two properties: detail and related. If you remember, in the previous article I've separated the two parts of the page in two different usercontrols. The purpose of these properties is to feed the two parts also in this HTML example.</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">/// <reference path="../../js/knockout-2.3.0.js" /></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #008000;">/// <reference path="../../js/knockout-winjs.js" /></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #008000;">/// <reference path="../../js/data.js" /></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">var</span> NamePageViewModel = (<span style="color: #0000ff;">function</span> ()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">function</span> NamePageViewModel(id)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">var</span> _this = <span style="color: #0000ff;">this</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> _this.detail = ko.observable(<span style="color: #0000ff;">new</span> NameDetailViewModel(id));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> _this.related = ko.observable(<span style="color: #0000ff;">new</span> RelatedNamesViewModel());</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">return</span> NamePageViewModel;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> })();</pre> <!--CRLF--></div> </div> <p>Each property is made observable because it is subject of binding to the corresponding View. In the page each part is represented by a div element and I use a special Knockout's binding that has the purpose of converting a property in the ViewModel of an element. It is the "with" binding:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">section</span> <span style="color: #ff0000;">aria-label</span><span style="color: #0000ff;">="Main content"</span> <span style="color: #ff0000;">role</span><span style="color: #0000ff;">="main"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="detail"</span> <span style="color: #ff0000;">data-bind</span><span style="color: #0000ff;">="<strong><span style="background-color: #ffff00; color: #ff0000;">with: detail</span></strong>"</span> <span style="color: #ff0000;">style</span><span style="color: #0000ff;">="margin: 80px 0px 0px 120px;"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.HtmlControl"</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{uri: '/views/NameDetail/NameDetail.html'}"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="related"</span> <span style="color: #ff0000;">data-bind</span><span style="color: #0000ff;">="<span style="background-color: #ffff00; color: #ff0000;"><strong>with: related</strong></span>"</span> <span style="color: #ff0000;">style</span><span style="color: #0000ff;">="margin: 80px 0px 0px 40px;"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.HtmlControl"</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{uri: '/views/RelatedNames/RelatedNames.html'}"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">section</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>The two parts of the interface are created as WinJS HtmlControls. They appear to be similar to a normal page with the sole difference they do not have a root <html> tag but they start with a <div> element. Here I show the RelatedNames.html page where I placed a ListView with the GridLayout. This grid is feeded by an observable property called "names". Unfortunately the ListView does not directly support KnockoutJS's binding because ist "itemDataSource" property is only exposed to Javascript and not as a plain html property. Have a look at the HTML:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="relatedGrid"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #ff0000;">data-bind</span><span style="color: #0000ff;">="listViewBinding: names"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="win-selectionstylefilled"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.ListView"</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{ </span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> itemTemplate: select('#itemTemplate'), </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> selectionMode: 'single', </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> tapBehavior: 'invokeOnly', </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> swipeBehavior: 'none', </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> layout: { type: WinJS.UI.GridLayout } }"<span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>The listViewBinding key into the "data-bind" attribute of the ListView is something I've created as an extension of KnockoutJS. It enables the binding of a plain observable, converted to a WinJS List, to the itemDataSource property of the ListView. The binding is a simple extension included in the downloadable example in the knockout-winjs.js file. Here it is:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> ko.bindingHandlers.listViewBinding = {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> init: <span style="color: #0000ff;">function</span> (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">var</span> observable = valueAccessor();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">var</span> data = observable();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> WinJS.UI.setOptions(element.winControl, { itemDataSource: <span style="color: #0000ff;">new</span> WinJS.Binding.List(data).dataSource })</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> update: <span style="color: #0000ff;">function</span> (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">var</span> observable = valueAccessor();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">var</span> data = observable();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> WinJS.UI.setOptions(element.winControl, { itemDataSource: <span style="color: #0000ff;">new</span> WinJS.Binding.List(data).dataSource })</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> };</pre> <!--CRLF--></div> </div> <p>The binding extension does two things: it handles initialization and updates connection the property it receive in the "valueAccessor" (it's a function, not a variable) and wraps it into a WinJS.Binding.List to provide a valid datasource to the ListView. The trick is that the return value of valueAccessor() is again a function from KnockoutJS that returns the observable array. </p> <p>So another step forward is done. Now, given that the html controls are in place for both the parts, we should have made all the bindings. You have to be aware that WinJS also have its binding system that usually is applied for item templates. It continue to work as usual, and you can to choose between the two ways every time, using the best that matches your goal. Now you should have the two parts working and we have to dive to get user interactions (clicks on ListView) and update according the other parts. We should add to the ListView another custom binding:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; height: 25px; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> data-bind="listViewBinding: names, <span style="background-color: #ffff00; color: #ff0000;"><strong>itemInvoked: itemClicked</strong></span>"</pre> <!--CRLF--></div> </div> <p>The new binding is required for the same reason of the previous. KnokoutJS contains a "click" binding that is usually fitted to handle click of elements to reflect them as commands in the ViewModel. Unfortunately Knockout is not aware of ListView so you need a custom binding to wire the itemInvoked event and map it to the view model. The event is someway similar to the other I shown but it have some tricky code:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> ko.bindingHandlers.itemInvoked = {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> element.winControl.oniteminvoked =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> function (e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> e.detail.itemPromise.then(function (item)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> var handler = valueAccessor();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> handler.apply(viewModel, [item.data, item.index]);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> element.winControl.oniteminvoked =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> function (e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> e.detail.itemPromise.then(function (item)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> var handler = valueAccessor();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> handler.apply(viewModel, [item.data, item.index]);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> }</pre> <!--CRLF--></div> </div> <p>The trick comes from the usage of the "apply" method to call the target method. The binding simply wires the oniteminvoked event of the element (using the winControl property). Then, when the event is catched, it calls the derired method on the viewmodel passing the viewmodel itself as context for the call. This enable the appropriate use of "this" into the viewmodel class, that differently would be unable to access its own instance.</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> RelatedNamesViewModel.prototype.itemClicked = <span style="color: #0000ff;">function</span> (item, index)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #008000;">// here this is pointed to the class itself</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> }</pre> <!--CRLF--></div> </div> <p>Finally, at the end of this long walk into the application flow, we need to send a notification to the other viewmodel as we did with the Messenger in XAML. Neither javascript or knockout have something that can help in this goal. Simple messenger does not exists so we have to create something by ourself. Here is a simple basic dispatcher that is able to receive messages and notify a number of registered subscribers:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">var</span> Dispatcher = (<span style="color: #0000ff;">function</span> ()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">function</span> Dispatcher()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">this</span>.subscribers = [];</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> Dispatcher.current = <span style="color: #0000ff;">new</span> Dispatcher();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Dispatcher.prototype.subscribe = <span style="color: #0000ff;">function</span> (handler)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">var</span> item = <span style="color: #0000ff;">this</span>.subscribers.indexOf(handler);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">if</span> (item == -1)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">this</span>.subscribers.push(handler);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> Dispatcher.prototype.send = <span style="color: #0000ff;">function</span> (message, arg)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">this</span>.subscribers.forEach(<span style="color: #0000ff;">function</span> (item)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> item(message, arg);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;">return</span> Dispatcher;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> })();</pre> <!--CRLF--></div> </div> <p>This example lacks many features, but is gives an idea about how to create its own messenger. You probably need to add methosd to unsubscribe, the capability of delivering targeted messages and so on but for the sake of this example it suffices. Here is hot to send a message:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> RelatedNamesViewModel.prototype.itemClicked = <span style="color: #0000ff;">function</span> (item, index)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Dispatcher.current.send(<span style="color: #006080;">"selected"</span>, item);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> }</pre> <!--CRLF--></div> </div> And here how you can subscribe to receive notifications: <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> Dispatcher.current.subscribe(<span style="color: #0000ff;">function</span> (message, arg)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> _this.name(arg.name);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> _this.gender(arg.gender);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> _this.description(arg.description);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> _this.origin(arg.origin);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> });</pre> <!--CRLF--></div> </div> <h3>Conclusions</h3> <p>In these months I've shown a number of features implemented by both html5 and xaml. As a conclusion I would like to remark that the purpose of this series was to enable people to easily migrate from a platform to the other when a customer requires an implementation in the language that is not yours. I'm really confident that this series will not move anyone from html to xaml or viceversa just because, as I'm strongly trained with xaml and I manage to use it every time I can just because it makes me fast as the light, someone may have the opposite feel. So I hope you may find useful reading these words and they help you to cross the line that separated these two representations of the same story.</p> http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Organize-your-UI-layer-in-HTML.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Organize-your-UI-layer-in-HTML.aspx#comments http://www.silverlightshow.net/items/Windows-Store-apps-with-XAML-and-HTML-Organize-your-UI-layer-in-HTML.aspx Tue, 24 Sep 2013 11:18:00 GMT Windows Store apps in HTML and XAML: Organize your UI layer in XAML <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Organize-your-UI-layer-in-XAML.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/1ajGZNv" data-text="#WindowsStore apps with #XAML & #HTML - Organize your UI layer in XAML. #win8dev" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Organize-your-UI-layer-in-XAML.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Organize-your-UI-layer-in-XAML.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/OrganizeUIWithXAML.zip">Download the source code for this article</a></strong> </div> <p>Having a deep knowledge of your toolset, when you start a new application from scratch, does not necessarily mean you are able to develop rapidly and effectively. The biggest problems, infact, do not come from the missing knowledge of a feature, that you can easily fill with a short search on the Internet, but from the grow of complexity of your application when you start putting things together without knowing exactly how you can better organize them to avoid the exponential increase of entropy.</p> <p>The first and much more important aspect is the architectural pattern, made of a set of classes that collaborate together, separating responsabilities between different actors in the UI layer. Be aware that I'm not speaking about the organization of the application tiers, usually separated in UI, Business Logic and Data but about a separation which is completely internal at the UI layer. </p> <p>Given that this series is about XAML and HTML, in these two last articles I'd like to compare the ways you can implement this separation of concerns, starting with XAML where the most consolidated pattern is called MVVM and then, in the next article, explain how to achieve a similar result in HTML using some additional library. So let start speaking about a similar example, implemented in both the platforms.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Advanced-MVVM-concepts-using-Contoso-Cookbook-An-analysis-of-a-complete-MVVM-application-Part-1.aspx">Gill Cleeren's article series: Advanced MVVM concepts using Contoso Cookbook</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-LOB-Apps-with-Kona-Getting-Started.aspx">Brian Noyes' series: WinRT Business Apps with Prism</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Background processing in Windows 8" src="http://www.silverlightshow.net/Storage/win8_background.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <h4>MVVM: anyone don't know?</h4> <p>So, sponsoring MVVM at this point is probably something unuseful, just because everyone embraced XAML is already aware that this pattern is surely the better way to deal with this environment. Model-View-VievModel is able to take advantage of some XAML specific peculiarities without mixing logic with interface. </p> <p>MVVM is made of three components, the View that you may consider the XAML file, the Model that are your entities. Finally, the ViewModel, as the name suggests is the adapter between your model and the view. Infact, it takes data coming from the lower layers, part of the model, it manipulates them to adapt them to the needs of the view. Also, it receives interactions of the user with the view and reflect them onto the model calling the required services.</p> <p>The key of the pattern is in separating carefully, both vertically and horizontally, the elements. The first question which you have to answer is "How many views (and viewmodels) I've to create?". When you first start with MVVM answer is probably "one per page". This is far away from the reality because, if it is true that a page is a view, it is completely false that there is only a single view per page. What you have to understand is that each part of the UI that atomically presents data and receives commands is a View and have a ViewModel. If you think at a grid, you may understand that each row has a ViewModel because it presents data from a single entity and receive commands (e.g. delete) related to it. Also if you break your page in different parts, probably it is convenient each part be a view and have a viewmodel. As a result the right answer is: "create as many views as it is convenient to horizontally separate the components of your UI". </p> <h4>A simple example</h4> <p>A common UI pattern in Windows Store is to present an item and a set of related contents. After a navigation you arrive to select an item and together with it the interface presents other items you may be interested, on the basis of a simple rule. Let say you have a page like this, where there's a list of related contents, presented as a gridview, and every time you click an item the currently shown detail changes. </p> <p><img width="699" height="394" title="screenshot_08312013_192322" style="margin: 5px auto 0px; float: none; display: block; background-image: none; border-width: 0px; border-style: solid;" alt="screenshot_08312013_192322" src="http://www.silverlightshow.net/Storage/Users/AndreaBoschin/screenshot_08312013_192322_df126a61-cc03-4998-99db-ff5c9f275a95.png" /></p> <p>The interface here presented can be easily separated in two parts, that are mostly indipendent each other. The first is the representation of a single item (an instance of PersonName) on the left of the screen. The other is a collection of related PersonName instances. They are presented with a GridView on the righ side. These components works separately except for one single thing that is the selection of an item of the GridView. When the item is clicked the other part loads the new item and changes the labels. So, we can easily think at the two parts like two separated UserControl, and they have an autonomous ViewModel. Here are they added to the page:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="40*"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="60*"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">vw:NameDetailView</span> <span style="color: #ff0000;">DataContext</span><span style="color: #0000ff;">="{Binding Detail}"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="120,80,0,0"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">vw:RelatedNamesView</span> <span style="color: #ff0000;">DataContext</span><span style="color: #0000ff;">="{Binding Related}"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="1"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="40,80,0,0"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>Also the Page has its own ViewModel that server as coordinator. It has the responsibility of reading the initially selected item and load the children view models:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> NameViewModel : ViewModelBase, ILoadable</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #cc6633;">#region</span> Detail property</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">private</span> NameDetailViewModel detail;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">public</span> NameDetailViewModel Detail</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> get { <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">this</span>.detail; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> set</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.detail != <span style="color: #0000ff;">value</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">this</span>.detail = <span style="color: #0000ff;">value</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">this</span>.RaisePropertyChanged(<span style="color: #006080;">"Detail"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> } </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #cc6633;">#region</span> Related property</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;">private</span> RelatedNamesViewModel related;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">public</span> RelatedNamesViewModel Related</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> get { <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">this</span>.related; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> set</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.related != <span style="color: #0000ff;">value</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> <span style="color: #0000ff;">this</span>.related = <span style="color: #0000ff;">value</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span> <span style="color: #0000ff;">this</span>.RaisePropertyChanged(<span style="color: #006080;">"Related"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> } </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> <span style="color: #0000ff;">public</span> NameViewModel()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span> <span style="color: #0000ff;">this</span>.Detail = <span style="color: #0000ff;">new</span> NameDetailViewModel();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span> <span style="color: #0000ff;">this</span>.Related = <span style="color: #0000ff;">new</span> RelatedNamesViewModel();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Load(<span style="color: #0000ff;">string</span> parameter)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum49" style="color: #606060;"> 49:</span> <span style="color: #0000ff;">int</span> id = 0;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum50" style="color: #606060;"> 50:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum51" style="color: #606060;"> 51:</span> <span style="color: #0000ff;">bool</span> success = <span style="color: #0000ff;">int</span>.TryParse(parameter, <span style="color: #0000ff;">out</span> id);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum52" style="color: #606060;"> 52:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum53" style="color: #606060;"> 53:</span> <span style="color: #0000ff;">if</span> (success)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum54" style="color: #606060;"> 54:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum55" style="color: #606060;"> 55:</span> IDataService data = <span style="color: #0000ff;">new</span> DataService();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum56" style="color: #606060;"> 56:</span> PersonName name = data.GetName(id);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum57" style="color: #606060;"> 57:</span> <span style="color: #0000ff;">this</span>.Detail.Load(name);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum58" style="color: #606060;"> 58:</span> <span style="color: #0000ff;">this</span>.Related.Load(name);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum59" style="color: #606060;"> 59:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum60" style="color: #606060;"> 60:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum61" style="color: #606060;"> 61:</span> }</pre> <!--CRLF--></div> </div> <p>This view model is the only that requires a short trick into the page codebehind. This is because it is not a ggod idea to load the ViewModel content into the ctor but you have to wait for the OnNavigated event where you get the id of the selected item coming from the navigation uri. So using a simple ILoadable interface I create a lightweight connection with the codebehind and you are able to create a base class for pages that implicitly does this operation:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">sealed</span> <span style="color: #0000ff;">partial</span> <span style="color: #0000ff;">class</span> NamePage : Page</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">public</span> NamePage()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">this</span>.InitializeComponent();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnNavigatedTo(NavigationEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> ILoadable vm = <span style="color: #0000ff;">this</span>.DataContext <span style="color: #0000ff;">as</span> ILoadable;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">if</span> (vm != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> vm.Load((<span style="color: #0000ff;">string</span>)e.Parameter);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--></div> </div> <p>The two user controls have an independent view model and act with a complete separation from the other. This enable to easily reuse this component and also to easily customize its graphical content and to unit test it. Here is the XAML from grid view User Control:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">GridView</span> <span style="color: #ff0000;">ItemsSource</span><span style="color: #0000ff;">="{Binding Names}"</span> <span style="color: #ff0000;">SelectionMode</span><span style="color: #0000ff;">="None"</span> <span style="color: #ff0000;">IsItemClickEnabled</span><span style="color: #0000ff;">="True"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">bh:Interaction.Behaviors</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">svc:EventToCommand</span> <span style="color: #ff0000;">Command</span><span style="color: #0000ff;">="{Binding ItemClickedCommand}"</span> <span style="color: #ff0000;">EventName</span><span style="color: #0000ff;">="ItemClick"</span> <span style="color: #ff0000;">UseEventArgs</span><span style="color: #0000ff;">="True"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">bh:Interaction.Behaviors</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">GridView.ItemsPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ItemsPanelTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">VariableSizedWrapGrid</span> <span style="color: #ff0000;">ItemWidth</span><span style="color: #0000ff;">="200"</span> <span style="color: #ff0000;">MaximumRowsOrColumns</span><span style="color: #0000ff;">="6"</span> <span style="color: #ff0000;">Orientation</span><span style="color: #0000ff;">="Vertical"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ItemsPanelTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">GridView.ItemsPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">GridView.ItemContainerStyle</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="GridViewItem"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="HorizontalAlignment"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Stretch"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="HorizontalContentAlignment"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Stretch"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">GridView.ItemContainerStyle</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">GridView.ItemTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Border</span> <span style="color: #ff0000;">BorderThickness</span><span style="color: #0000ff;">="10,0,0,0"</span> <span style="color: #ff0000;">BorderBrush</span><span style="color: #0000ff;">="{Binding Gender, Converter={StaticResource Bool2GenderColor}}"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,20,0,0"</span> <span style="color: #ff0000;">Padding</span><span style="color: #0000ff;">="20,0,0,0"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource SubheaderTextStyle}"</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="{Binding Name}"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Border</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">GridView.ItemTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">GridView</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>In this snippet you can see that the ViewModel exposes a "Names" property. It is connected via Binding to the ItemsSource property of the GridView. Each generated item is connected to the properties it has to display and a converter is used to map the boolean value representing the Gender to a color (Pink or Azure). The ViewModel is very simple in its structure. It does not contains any property that is strictly related with a "UI" concern. There is not a "NameColor" property but the conversion is made in the converter leaving the interpretation of the "Gender" information to the designer that is able to express it as a color or as a string on the basis of his personal feel. This ia an important concept to keep in mind while you design your ViewModel. It is only a agnostic representation of the information needed to the View but it does not have any "graphical" information. Properties like "IsVisible", "IsEnabled", etc are strongly discouraged but they must come from an interpretation of a particular condition of the ViewModel's data. The ViewModel is pretty simple:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> RelatedNamesViewModel: ViewModelBase</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">public</span> ObservableCollection<PersonName> Names { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">public</span> RelayCommand<ItemClickEventArgs> ItemClickedCommand { get; set; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">public</span> RelatedNamesViewModel()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">this</span>.Names = <span style="color: #0000ff;">new</span> ObservableCollection<PersonName>();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">this</span>.ItemClickedCommand = <span style="color: #0000ff;">new</span> RelayCommand<ItemClickEventArgs>(ItemClicked);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> ItemClicked(ItemClickEventArgs args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">this</span>.MessengerInstance.Send<PersonName>((PersonName)args.ClickedItem, <span style="color: #006080;">"NameSelected"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Load(PersonName name)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> DataService service = <span style="color: #0000ff;">new</span> DataService();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> IEnumerable<PersonName> names = service.GetRelated(name.Id);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;">this</span>.Names.Clear();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">foreach</span>(var item <span style="color: #0000ff;">in</span> names)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">this</span>.Names.Add(item);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> }</pre> <!--CRLF--></div> </div> <p>Each ViewModel has three specific sections: Initialization (in the constructor) where properties are initialized to a default value; Loading is the method that is responsible to call the Model and load the retrieved information to the properties. Finally the other section is related to the command handling. In this particular case the ViewModel handles the command coming from the ItemClick event. Here I use the RelayCommand class from the MVVM Light Toolkit.</p> <p>The command is not handled directly inside the ViewModel because it has to be notified to the other part of the View. This is made sending a "broadcast message" with the Messenger (also part of the MVVM Light Toolkit). Broadcasting a message instead of handling all into a single ViewModel has a number of advantages. This let you, as an example, to add in the future other View (and ViewModels) that subscribe to the message and act adding other information, like "suggested variants", "other people choices", etc... You are not forced to put all this logic together in the same ViewModel but you can build the "bricks", one by one, when you really need them. </p> <p>The messenger gets a name for the event. To give a name to this event is not a trivial task. When I name the event I prefer to choose an agnostic name (in the case "NameSelected") instead to something that say what it is expected to happen (e.g. "ShowItem"). This make it easy to interpret the message in different ways in the future.</p> <p>The other ViewModel receives the message and update the item to be displayed simply calling again the Load method:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> NameDetailViewModel : ViewModelBase</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #cc6633;">#region</span> Item property</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">private</span> PersonName item;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">public</span> PersonName Item</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> get { <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">this</span>.item; }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> set</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.item != <span style="color: #0000ff;">value</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">this</span>.item = <span style="color: #0000ff;">value</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">this</span>.RaisePropertyChanged(<span style="color: #006080;">"Item"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;">public</span> NameDetailViewModel()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;">this</span>.MessengerInstance.Register<PersonName>(<span style="color: #0000ff;">this</span>, <span style="color: #006080;">"NameSelected"</span>, Load);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Load(PersonName item)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #0000ff;">this</span>.Item = item;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> }</pre> <!--CRLF--></div> </div> <p>The item property uses the INotifyPropertyChanged interface to make the View aware of the change. Also in this case I use the MVVM Light Toolkit to raise the event, inheriting the ViewModel from the ViewModelBase class. It exposes the RaisePropertyChanged method that does all the work.</p> <h4>Map Events to commands.</h4> <p>In Windows Store Apps, like in Silverlight, only Button and HyperlinkButton natively support the Command pattern. So to map the ItemClick event to the ViewModel you need to apply a trick. The most simple is to operate in the codebehind, but you can search Nuget for a library called "WinRtBehaviors". This library is an implementation of Blend Behaviors worte for WinRt and on the basis of its code you can create a simple behavior called "EventToCommand" to map an event to a command using only the markup and Binding extension.</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> EventToCommand : Behavior<FrameworkElement></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #cc6633;">#region</span> EventName</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> DependencyProperty EventNameProperty =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> DependencyProperty.Register(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #006080;">"EventName"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">typeof</span>(<span style="color: #0000ff;">string</span>),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">typeof</span>(EventToCommand),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">new</span> PropertyMetadata(<span style="color: #0000ff;">null</span>));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> EventName</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> get { <span style="color: #0000ff;">return</span> (<span style="color: #0000ff;">string</span>)GetValue(EventNameProperty); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> set { SetValue(EventNameProperty, <span style="color: #0000ff;">value</span>); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #cc6633;">#region</span> Command</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> DependencyProperty CommandProperty =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> DependencyProperty.Register(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #006080;">"Command"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">typeof</span>(ICommand),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">typeof</span>(EventToCommand),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;">new</span> PropertyMetadata(<span style="color: #0000ff;">null</span>));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #0000ff;">public</span> ICommand Command</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> get { <span style="color: #0000ff;">return</span> (ICommand)GetValue(CommandProperty); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> set { SetValue(CommandProperty, <span style="color: #0000ff;">value</span>); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span> <span style="color: #cc6633;">#region</span> CommandParameter</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> DependencyProperty CommandParameterProperty =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> DependencyProperty.Register(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> <span style="color: #006080;">"CommandParameter"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> <span style="color: #0000ff;">typeof</span>(<span style="color: #0000ff;">object</span>),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span> <span style="color: #0000ff;">typeof</span>(EventToCommand),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span> <span style="color: #0000ff;">new</span> PropertyMetadata(<span style="color: #0000ff;">null</span>));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">object</span> CommandParameter</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> get { <span style="color: #0000ff;">return</span> (<span style="color: #0000ff;">object</span>)GetValue(CommandParameterProperty); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum49" style="color: #606060;"> 49:</span> set { SetValue(CommandParameterProperty, <span style="color: #0000ff;">value</span>); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum50" style="color: #606060;"> 50:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum51" style="color: #606060;"> 51:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum52" style="color: #606060;"> 52:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum53" style="color: #606060;"> 53:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum54" style="color: #606060;"> 54:</span> <span style="color: #cc6633;">#region</span> UseEventArgs</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum55" style="color: #606060;"> 55:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum56" style="color: #606060;"> 56:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> DependencyProperty UseEventArgsProperty =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum57" style="color: #606060;"> 57:</span> DependencyProperty.Register(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum58" style="color: #606060;"> 58:</span> <span style="color: #006080;">"UseEventArgs"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum59" style="color: #606060;"> 59:</span> <span style="color: #0000ff;">typeof</span>(<span style="color: #0000ff;">bool</span>),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum60" style="color: #606060;"> 60:</span> <span style="color: #0000ff;">typeof</span>(EventToCommand),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum61" style="color: #606060;"> 61:</span> <span style="color: #0000ff;">new</span> PropertyMetadata(<span style="color: #0000ff;">null</span>));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum62" style="color: #606060;"> 62:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum63" style="color: #606060;"> 63:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> UseEventArgs</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum64" style="color: #606060;"> 64:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum65" style="color: #606060;"> 65:</span> get { <span style="color: #0000ff;">return</span> (<span style="color: #0000ff;">bool</span>)GetValue(UseEventArgsProperty); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum66" style="color: #606060;"> 66:</span> set { SetValue(UseEventArgsProperty, <span style="color: #0000ff;">value</span>); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum67" style="color: #606060;"> 67:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum68" style="color: #606060;"> 68:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum69" style="color: #606060;"> 69:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum70" style="color: #606060;"> 70:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum71" style="color: #606060;"> 71:</span> <span style="color: #cc6633;">#region</span> Handlers</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum72" style="color: #606060;"> 72:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum73" style="color: #606060;"> 73:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnAttached()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum74" style="color: #606060;"> 74:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum75" style="color: #606060;"> 75:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.AssociatedObject != <span style="color: #0000ff;">null</span> &&</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum76" style="color: #606060;"> 76:</span> !<span style="color: #0000ff;">string</span>.IsNullOrEmpty(<span style="color: #0000ff;">this</span>.EventName))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum77" style="color: #606060;"> 77:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum78" style="color: #606060;"> 78:</span> EventInfo eventInfo = <span style="color: #0000ff;">this</span>.GetEventInfo(<span style="color: #0000ff;">this</span>.AssociatedObject.GetType(), <span style="color: #0000ff;">this</span>.EventName);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum79" style="color: #606060;"> 79:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum80" style="color: #606060;"> 80:</span> <span style="color: #0000ff;">if</span> (eventInfo != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum81" style="color: #606060;"> 81:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum82" style="color: #606060;"> 82:</span> Delegate handler = <span style="color: #0000ff;">this</span>.GetEventHandler(eventInfo);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum83" style="color: #606060;"> 83:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum84" style="color: #606060;"> 84:</span> WindowsRuntimeMarshal.AddEventHandler<Delegate>(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum85" style="color: #606060;"> 85:</span> dlg => (EventRegistrationToken)eventInfo.AddMethod.Invoke(<span style="color: #0000ff;">this</span>.AssociatedObject, <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>[] { dlg }),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum86" style="color: #606060;"> 86:</span> etr => eventInfo.RemoveMethod.Invoke(<span style="color: #0000ff;">this</span>.AssociatedObject, <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>[] { etr }), handler);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum87" style="color: #606060;"> 87:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum88" style="color: #606060;"> 88:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum89" style="color: #606060;"> 89:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum90" style="color: #606060;"> 90:</span> <span style="color: #0000ff;">base</span>.OnAttached();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum91" style="color: #606060;"> 91:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum92" style="color: #606060;"> 92:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum93" style="color: #606060;"> 93:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnDetaching()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum94" style="color: #606060;"> 94:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum95" style="color: #606060;"> 95:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.AssociatedObject != <span style="color: #0000ff;">null</span> &&</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum96" style="color: #606060;"> 96:</span> !<span style="color: #0000ff;">string</span>.IsNullOrEmpty(<span style="color: #0000ff;">this</span>.EventName))</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum97" style="color: #606060;"> 97:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum98" style="color: #606060;"> 98:</span> EventInfo eventInfo = <span style="color: #0000ff;">this</span>.GetEventInfo(<span style="color: #0000ff;">this</span>.AssociatedObject.GetType(), <span style="color: #0000ff;">this</span>.EventName);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum99" style="color: #606060;"> 99:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum100" style="color: #606060;"> 100:</span> <span style="color: #0000ff;">if</span> (eventInfo != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum101" style="color: #606060;"> 101:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum102" style="color: #606060;"> 102:</span> Delegate handler = <span style="color: #0000ff;">this</span>.GetEventHandler(eventInfo);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum103" style="color: #606060;"> 103:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum104" style="color: #606060;"> 104:</span> WindowsRuntimeMarshal.RemoveEventHandler<Delegate>(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum105" style="color: #606060;"> 105:</span> etr => eventInfo.RemoveMethod.Invoke(<span style="color: #0000ff;">this</span>.AssociatedObject, <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>[] { etr }), handler);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum106" style="color: #606060;"> 106:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum107" style="color: #606060;"> 107:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum108" style="color: #606060;"> 108:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum109" style="color: #606060;"> 109:</span> <span style="color: #0000ff;">base</span>.OnDetaching();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum110" style="color: #606060;"> 110:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum111" style="color: #606060;"> 111:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum112" style="color: #606060;"> 112:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum113" style="color: #606060;"> 113:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum114" style="color: #606060;"> 114:</span> <span style="color: #cc6633;">#region</span> Event Management</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum115" style="color: #606060;"> 115:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum116" style="color: #606060;"> 116:</span> <span style="color: #0000ff;">private</span> EventInfo GetEventInfo(Type type, <span style="color: #0000ff;">string</span> eventName)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum117" style="color: #606060;"> 117:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum118" style="color: #606060;"> 118:</span> EventInfo eventInfo = type.GetTypeInfo().GetDeclaredEvent(eventName);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum119" style="color: #606060;"> 119:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum120" style="color: #606060;"> 120:</span> <span style="color: #0000ff;">if</span> (eventInfo == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum121" style="color: #606060;"> 121:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum122" style="color: #606060;"> 122:</span> Type baseType = type.GetTypeInfo().BaseType;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum123" style="color: #606060;"> 123:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum124" style="color: #606060;"> 124:</span> <span style="color: #0000ff;">if</span> (baseType != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum125" style="color: #606060;"> 125:</span> <span style="color: #0000ff;">return</span> GetEventInfo(type.GetTypeInfo().BaseType, eventName);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum126" style="color: #606060;"> 126:</span> <span style="color: #0000ff;">else</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum127" style="color: #606060;"> 127:</span> <span style="color: #0000ff;">return</span> eventInfo;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum128" style="color: #606060;"> 128:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum129" style="color: #606060;"> 129:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum130" style="color: #606060;"> 130:</span> <span style="color: #0000ff;">return</span> eventInfo;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum131" style="color: #606060;"> 131:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum132" style="color: #606060;"> 132:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum133" style="color: #606060;"> 133:</span> <span style="color: #008000;">/// <summary></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum134" style="color: #606060;"> 134:</span> <span style="color: #008000;">/// Create an instance of a delegate able to handle the provided event</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum135" style="color: #606060;"> 135:</span> <span style="color: #008000;">/// </summary></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum136" style="color: #606060;"> 136:</span> <span style="color: #008000;">/// <param name="eventInfo">Information about the event to create the delegate</param></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum137" style="color: #606060;"> 137:</span> <span style="color: #008000;">/// <returns></returns></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum138" style="color: #606060;"> 138:</span> <span style="color: #0000ff;">public</span> Delegate GetEventHandler(EventInfo eventInfo)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum139" style="color: #606060;"> 139:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum140" style="color: #606060;"> 140:</span> Delegate dlg = <span style="color: #0000ff;">null</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum141" style="color: #606060;"> 141:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum142" style="color: #606060;"> 142:</span> <span style="color: #0000ff;">if</span> (eventInfo == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum143" style="color: #606060;"> 143:</span> <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> ArgumentNullException(<span style="color: #006080;">"eventInfo"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum144" style="color: #606060;"> 144:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum145" style="color: #606060;"> 145:</span> <span style="color: #0000ff;">if</span> (eventInfo.EventHandlerType == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum146" style="color: #606060;"> 146:</span> <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> ArgumentNullException(<span style="color: #006080;">"eventInfo.EventHandlerType"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum147" style="color: #606060;"> 147:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum148" style="color: #606060;"> 148:</span> <span style="color: #0000ff;">if</span> (dlg == <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum149" style="color: #606060;"> 149:</span> dlg = <span style="color: #0000ff;">this</span>.GetType()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum150" style="color: #606060;"> 150:</span> .GetTypeInfo()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum151" style="color: #606060;"> 151:</span> .GetDeclaredMethod(<span style="color: #006080;">"OnEventRaised"</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum152" style="color: #606060;"> 152:</span> .CreateDelegate(eventInfo.EventHandlerType, <span style="color: #0000ff;">this</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum153" style="color: #606060;"> 153:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum154" style="color: #606060;"> 154:</span> <span style="color: #0000ff;">return</span> dlg;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum155" style="color: #606060;"> 155:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum156" style="color: #606060;"> 156:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum157" style="color: #606060;"> 157:</span> <span style="color: #008000;">/// <summary></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum158" style="color: #606060;"> 158:</span> <span style="color: #008000;">/// Received the notifications when the wrapped event has been raised.</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum159" style="color: #606060;"> 159:</span> <span style="color: #008000;">/// </summary></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum160" style="color: #606060;"> 160:</span> <span style="color: #008000;">/// <param name="sender">source of the event</param></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum161" style="color: #606060;"> 161:</span> <span style="color: #008000;">/// <param name="e">arguments of the event</param></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum162" style="color: #606060;"> 162:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> OnEventRaised(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum163" style="color: #606060;"> 163:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum164" style="color: #606060;"> 164:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.Command != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum165" style="color: #606060;"> 165:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum166" style="color: #606060;"> 166:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.UseEventArgs)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum167" style="color: #606060;"> 167:</span> <span style="color: #0000ff;">this</span>.Command.Execute(e);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum168" style="color: #606060;"> 168:</span> <span style="color: #0000ff;">else</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum169" style="color: #606060;"> 169:</span> <span style="color: #0000ff;">this</span>.Command.Execute(<span style="color: #0000ff;">this</span>.CommandParameter);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum170" style="color: #606060;"> 170:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum171" style="color: #606060;"> 171:</span> } </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum172" style="color: #606060;"> 172:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum173" style="color: #606060;"> 173:</span> <span style="color: #cc6633;">#endregion</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum174" style="color: #606060;"> 174:</span> }</pre> <!--CRLF--></div> </div> <p>The class is able to attach an event got from the EventName property and when the event is raised it call the ICommand instance attached by Binding to the Command property. The code in this snipped is slightly complex but its inner working is out of the topic of this article. You can easily use it as-is in your projects and you can attach an event with a code like this:</p> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">GridView</span> <span style="color: #ff0000;">ItemsSource</span><span style="color: #0000ff;">="{Binding Names}"</span> <span style="color: #ff0000;">SelectionMode</span><span style="color: #0000ff;">="None"</span> <span style="color: #ff0000;">IsItemClickEnabled</span><span style="color: #0000ff;">="True"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">bh:Interaction.Behaviors</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">svc:EventToCommand</span> <span style="color: #ff0000;">Command</span><span style="color: #0000ff;">="{Binding ItemClickedCommand}"</span> <span style="color: #ff0000;">EventName</span><span style="color: #0000ff;">="ItemClick"</span> <span style="color: #ff0000;">UseEventArgs</span><span style="color: #0000ff;">="True"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">bh:Interaction.Behaviors</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #008000;"><!-- other code --></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">GridView</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>You can download complete example attached to this article. I hope it can help you to give a better structure to your Windows Store projects and make them much more maintainable and testable. </p> <h4>Waiting for HTML</h4> <p>Starting from the attached sample you can create your own toolset, made of base classes, behaviors and converters, to better support MVVM in your Windows Store projects. The next (and last) article in this series will show how to implements MVVM with HTML in a windows Store app.</p> http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Organize-your-UI-layer-in-XAML.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Organize-your-UI-layer-in-XAML.aspx#comments http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Organize-your-UI-layer-in-XAML.aspx Mon, 09 Sep 2013 13:48:00 GMT Windows Store apps in HTML and XAML: Animations and transitions <p style="text-align: justify;">Up to Windows 8, we were used to see software that was static from the UI point of view. Most of the times the program showed forms and dialogs without any license to the eye pleasure, without using any form of animation to introduce functions and requests. This was mostly because of the low power of previous systems but also because, deal with animations was an hard and costly task that tipically remained an unsatisfied desire.</p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Advanced-MVVM-concepts-using-Contoso-Cookbook-An-analysis-of-a-complete-MVVM-application-Part-1.aspx">Gill Cleeren's article series: Advanced MVVM concepts using Contoso Cookbook</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-LOB-Apps-with-Kona-Getting-Started.aspx">Brian Noyes' series: WinRT Business Apps with Prism</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">WPF and Silverlight introduced a wide toolset for animations, unfortunately it was still too much complex to be handled in a right way. Animations are something that need to be carefully planned, designed and driven, so, also is much more advanced and easy than the past, people simply omitted to use them widely.</p> <p style="text-align: justify;">With Windows 8 and Store Applications, the animations not only became one of the pillars of a beautiful application, making it much more appealing for the market, but it is now also a fact of usability that communicate fluidness and effectiveness to the user while he is using the interface. For this being easy for developers, the framework introduced a set of animations and transitions that are predefined and ready for a whole set of common interface patterns</p> <h4 style="text-align: justify;">XAML and HTML: two different ways</h4> <p style="text-align: justify;">When dealing with animations and transitions, HTML and XAML work in a very different way. There is not any reason to think that one is better than the other, because the way they works depends from their intrinsic nature. </p> <p style="text-align: justify;">With XAML it is easy to create animations like attachable behaviors, extending the markup with specific tags and properties. And it is the way they choose to go. Each visual element contains some properties made to apply some kind of transition and for animations they exists a predefined set to be used. </p> <p style="text-align: justify;">HTML instead is not easily extensible like XAML so, to create a toolset they decided to add a specific namespace to WinJS. It is WinJS.UI.Animation. Inside this namespace one find the required methods that are able to create the animation, passing the needed actors as an argument. Let see an example:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel.ChildrenTransitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TransitionCollection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">EntranceThemeTransition</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">TransitionCollection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel.ChildrenTransitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The previous snippet shows a transition that apply to the children of a stack panel. When you add or remove a children from the panel, it is subject to an animation from right to left to emphasize the entrance. This same animation can be also applied to the ItemsControl via ItemContainerTransition property:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ItemsControl.ItemContainerTransitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TransitionCollection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">EntranceThemeTransition</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">TransitionCollection</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ItemsControl.ItemContainerTransitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">So, when you add an item to the Items collection it has automatically applied the same transition. This is really useful for every control that derives from ItemsControl, like GridViews and ListViews. </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Button_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">this</span>.items.Items.Insert(0,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">new</span> Ellipse </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> { </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> Width = 50.0, </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> Height = 50.0, </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Fill = <span style="color: #0000ff;">new</span> SolidColorBrush(Colors.Red), </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> Margin = <span style="color: #0000ff;">new</span> Thickness(5.0) </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">To achieve a similar (but not equal) effect in HTML you have to prepare your animation from the Javascript code. So you have first to locate your container, the eventually affected elements, then you create the new element and setup the animation just before adding the element to the container. Finally you need to manually start the transition calling the execute() method. Here is an example:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> function AddElementWithTransition()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #008000;">// locate the container</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> var list = element.querySelector(<span style="color: #006080;">"#theContainer"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #008000;">// find elements that is affected by the animation (they may move when an element is added)</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> var affectedItems = document.querySelectorAll(<span style="color: #006080;">".listItem"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #008000;">// create the new item to add</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> var newItem = document.createElement(<span style="color: #006080;">"div"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> newItem.className = <span style="color: #006080;">"listItem"</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> newItem.style.background = randomColor();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #008000;">// setup the animation</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> var addToList = WinJS.UI.Animation.createAddToListAnimation(newItem, affectedItems);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #008000;">// insert the new item into the collection</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> list.insertBefore(newItem, list.firstChild);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #008000;">// execute the transition</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> addToList.execute();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">So, playing with transitions with HTML is not so simple as it is with XAML but as I've already said, this depends on the way the languages works. Up to here we have seen only animations that applies to collections. There are definitely other animations that apply to single object. In the following example you can see how to apply a fade in/out to an HTML element.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var item = document.querySelectorAll(<span style="color: #006080;">"#item"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #008000;">// fade in</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> WinJS.UI.Animation.fadeIn(item);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #008000;">// fade out</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> WinJS.UI.Animation.fadeOut(item);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This is also available in XAML with the specific FadeInThemeAnimation and FadeOutThemeAnimation. These are real animations and not transitions so you have to add them to a storyboard and the invoke the Begin method as you would do with a DoubleAnimation. They are actually a shortcut to have a predefined fade to attach to an element:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="FadeIn"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FadeInThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="FadeOut"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FadeOutThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="root"</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="{StaticResource ApplicationPageBackgroundThemeBrush}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Ellipse</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="100"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="100"</span> <span style="color: #ff0000;">Fill</span><span style="color: #0000ff;">="Orange"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #ff0000;">PointerEntered</span><span style="color: #0000ff;">="button_PointerEntered"</span> <span style="color: #ff0000;">PointerExited</span><span style="color: #0000ff;">="button_PointerExited"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Then in C# you have to handle the events and call the right storyboard begin method. Given that they are animation, you can manipulate their properties to change duration, speed, begin time and so on.</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnNavigatedTo(NavigationEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> FadeOut.Begin();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button_PointerEntered(<span style="color: #0000ff;">object</span> sender, PointerRoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> FadeIn.Begin();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button_PointerExited(<span style="color: #0000ff;">object</span> sender, PointerRoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> FadeOut.Begin();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">You are also enabled to use these animation with VisualStateManager, that means apply them also to ControlTemplates with all the benefit you can figure out. There are a number of animations available, and you can simply exchange on with the other to change the effect. Here is an example that emulates the pointer up/down effect as it works with clickable elements:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="FadeIn"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">PointerDownThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="FadeOut"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">PointerUpThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">As for fading, this is also available in HTML with the corresponding pointerUp and pointerDown methods:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> var item = document.querySelectorAll("#item");</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> // fade in</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> WinJS.UI.Animation.pointerDown(item);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> // fade out</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> WinJS.UI.Animation.pointerUp(item);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">You have to be aware that Javascript has an important advantage here. Infact the "item" can be expressed in different ways, and not only as a single object. If you use the querySelectorAll method, you can pass a number of items to the method and have all the items to be affected by the animation, In XAML you have to create a new instance of animation for each element and then include all in the same Storyboard. Not so clean.</p> <h4 style="text-align: justify;">Handling the lifetime.</h4> <p style="text-align: justify;">Lifetime with animation is important, specifically when you need to do something at the end of an animation. As an example you can concatenate an animation to another or setup the backward animation for an element. For this need in XAML you only have the Complete event that is raised when the animation goes to the end. This event may be handled easily in C#:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="PointerDown"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">PointerDownThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="FadeIn"</span> <span style="color: #ff0000;">Completed</span><span style="color: #0000ff;">="FadeInThemeAnimation_Completed"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FadeInThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="PointerUp"</span> <span style="color: #ff0000;">Completed</span><span style="color: #0000ff;">="PointerUpThemeAnimation_Completed"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">PointerUpThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Storyboard</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="FadeOut"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">FadeOutThemeAnimation</span> <span style="color: #ff0000;">TargetName</span><span style="color: #0000ff;">="ellipse"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Storyboard</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.Resources</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">After setting up these animation you can drive them in code:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button_PointerEntered(<span style="color: #0000ff;">object</span> sender, PointerRoutedEventArgs e) { FadeIn.Begin(); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button_PointerExited(<span style="color: #0000ff;">object</span> sender, PointerRoutedEventArgs e) { PointerUp.Begin(); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> PointerUpThemeAnimation_Completed(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e) { FadeOut.Begin(); }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FadeInThemeAnimation_Completed(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e) { PointerDown.Begin(); }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This creates a double effect that merges the fading with the pointer animations. To achieve a similar result you can use promises in Javascript. Each animation you setup is exposed as a promise so you can use the .then() and .done() methods to concatenate and drive other animations. </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> function onPointerDown(evt) {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> WinJS.UI.Animation.pointerUp(evt.srcElement).then(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> function ()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> WinJS.UI.Animation.fadeOut(evt.srcElement);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> function onPointerUp(evt) {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> WinJS.UI.Animation.fadeIn(evt.srcElement).then(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> function ()</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> WinJS.UI.Animation.pointerDown(evt.srcElement);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> });</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">At the very end, using promises is much more easy than events, just because you only need to figure out the sequence and write it in code. Using events make your code hard to be read. </p> <h4 style="text-align: justify;">Taking advantage of animation and transitions</h4> <p style="text-align: justify;">As I said at the very beginning of the article, there is a huge benefit from using animations and transitions. They are specifically targeted to give a fedback to the user that is important expecially when dealing with touch interfaces. In these cases infact, rollover effects that are common when the mouse is the main pointing device, becomes unuseful with fingers. Additionally, an animated interface gives a impression of fluidity that make the user aware of what is happening. </p> <p style="text-align: justify;">It is really important to use animations, almost as important as it is not to abuse of them. You have to have always in mind that:</p> <ol> <li> <div style="text-align: justify;">use always the same animation for the same action. Having different animations applied for the same actions is for source of confusion for the final user. </div> </li> <li> <div style="text-align: justify;">be always aware of the status of your animation. Please do not forget to reset them to the initial status when required because differently the can create ugly effects on you interface</div> </li> <li> <div style="text-align: justify;">animations as heavy. So please avoid to animate a numebr of items together (as in a gridview) because the user will be forced to wait a long time for the animation to end. </div> </li> </ol> <p style="text-align: justify;">These suggestion applies both to HTML and XAML. No matter the toolset you use, what really means it the result you achieve.</p> http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Animations-and-transitions.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Animations-and-transitions.aspx#comments http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Animations-and-transitions.aspx Thu, 15 Aug 2013 07:35:00 GMT Windows Store apps in HTML and XAML: Application bars, flyouts and other amenities <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Application-bars-flyouts-an-other-amenities.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Application-bars-flyouts-an-other-amenities.aspx" data-count="horizontal" data-text="#WindowsStore apps with #XAML & #HTML - Application bars, flyouts & other amenities. #win8dev" data-url="http://slshow.net/1bofYep">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Application-bars-flyouts-an-other-amenities.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Advanced-MVVM-concepts-using-Contoso-Cookbook-An-analysis-of-a-complete-MVVM-application-Part-1.aspx">Gill Cleeren's article series: Advanced MVVM concepts using Contoso Cookbook</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-LOB-Apps-with-Kona-Getting-Started.aspx">Brian Noyes' series: WinRT Business Apps with Prism</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">When you develop a Windows Store application, a big deal is to find a place for every feature, connecting together the available space with a reliable user experience. Together with the canvas of the application, Windows Store apps give you some other "surfaces" where you can collocate your commands and features, most of the times following the strict rules that have been collected under the UX Guidelines. These so called "surfaces" have the intent of create additional room with the purpose of leaving the interface more clean and simple, without omitting important features that are discoverable using common gestures. Swipe to side of the screen, tap & hold and other gestures bring the user to open expected that appear on demand to accomplish additional tasks.</p> <h3 style="text-align: justify;">The AppBar "surface"</h3> <p style="text-align: justify;">When an application is opened, most of the times it shows only the main canvas area. This surface contains the main content, often displayed using a GridView that creates the illusion of a potentially infinite space horizontally, but if the application follows the ux guidelines it does not show any evident command. Usually the first place where you have to search is the Application bar. The application bar appears when you swipe the top or bottom side and cant contain a number of items, expecially commands in the lower one and navigation items in the top one.</p> <p style="text-align: justify;">Defining an Application bar is slightly different in XAML and HTML. Since in XAML there are some properties that you may assign using markup, in HTML you have a WinJS control in which you define the layout of the items. Let see an example for each language:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.BottomAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Orientation</span><span style="color: #0000ff;">="Horizontal"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource RefreshAppBarButtonStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource FavoriteAppBarButtonStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Orientation</span><span style="color: #0000ff;">="Horizontal"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Right"</span> <span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource RefreshAppBarButtonStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource SettingsAppBarButtonStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">AppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.BottomAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This snippets defines a bottom application bar (look at the BottomAppBar property). Inside the application bar it is contained a Grid with two horizontal StackPanels. The purpose of the stack panels is to create two areas to host a number of buttons left and right aligned. As you can see the buttons are defined simply using a Style that is peeked up by the StandardStyles.xaml file. (Please take note that in Windows 8.1 this file has been embedded directly into the framework) These styles are a collection of buttons that include icons and titles in a standardized way. Let see the same example in HTML:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="bottomAppBar"</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.AppBar"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">button</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.AppBarCommand"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{label:'Refresh', icon:'refresh', section:'selection'}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">button</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.AppBarCommand"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{label:'Favorite', icon:'favorite', section:'selection'}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">button</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.AppBarCommand"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{label:'Refresh', icon:'refresh', section:'global'}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">button</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.AppBarCommand"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{label:'Settings', icon:'settings', section:'global'}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The main difference in this definition is in the way commands are positioned. At the first sight is appear there is not any specification but the "section" property defines two areas in the appbar named "global" and "selection". The name comes from the function of this area. Since the "global" section is for always-available commands and it maps to the right, the "selection" area is for commands that are contextual to the selection. This area maps to the left.</p> <p style="text-align: justify;">In html and xaml it is possible to define a custom layout that is commonly used for navigation purposes in the top appbar. To understand better the meaning of "navigation" think at the top appbar in Internet Explorer. This area shows the pages that are currently opened in the browser. Here is an example in XAML:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Page.TopAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">AppBar</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="topAppBar"</span> <span style="color: #ff0000;">IsSticky</span><span style="color: #0000ff;">="False"</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="#FF232323"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ScrollViewer</span> <span style="color: #ff0000;">HorizontalScrollBarVisibility</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #ff0000;">VerticalScrollBarVisibility</span><span style="color: #0000ff;">="Hidden"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ItemsControl</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="images"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ItemsControl.ItemsPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ItemsPanelTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Orientation</span><span style="color: #0000ff;">="Horizontal"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ItemsPanelTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ItemsControl.ItemsPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ItemsControl.ItemTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="5,5,5,18"</span> <span style="color: #ff0000;">Tag</span><span style="color: #0000ff;">="{Binding}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Image</span> <span style="color: #ff0000;">Source</span><span style="color: #0000ff;">="{Binding Uri}"</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="180"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="135"</span> <span style="color: #ff0000;">Stretch</span><span style="color: #0000ff;">="UniformToFill"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource TitleTextStyle}"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Right"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Bottom"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="{Binding Title}"</span> <span style="color: #ff0000;">Foreground</span><span style="color: #0000ff;">="White"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,0,0"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">DataTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ItemsControl.ItemTemplate</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ItemsControl</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ScrollViewer</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">AppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Page.TopAppBar</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">In this example the top appbar contains an horizontal stacked itemscontrol that is wrapped by a scrollviewer. Thanks to this layout the panel shows a selectable and scrollable list of items emulating the behavior of internet explorer. So please don't blame me if I don't show the same in HTML but a similar example would take all the article to be shown and explained. If you are intersted in please visit this page: <a href="http://girijashankarbeuria.wordpress.com/2013/06/04/winjs-appbar-tabbed-control-with-listview/" title="http://girijashankarbeuria.wordpress.com/2013/06/04/winjs-appbar-tabbed-control-with-listview/">http://girijashankarbeuria.wordpress.com/2013/06/04/winjs-appbar-tabbed-control-with-listview/</a> that has a complete example.</p> <h3 style="text-align: justify;">Popups vs Flyouts</h3> <p style="text-align: justify;">The AppBar is only the most simple and common alternative place to create more room for functions. When the AppBar does not suffice you can embrace the 3rd dimension and go with Popups and Flyouts. These items have been created to present popup elements and, until the availability of Windows 8.1, they are one for XAML (popups) and the other for HTML (flyouts). When Windows 8.1 will be public, XAML will get also a Flyout controls that has been widely requested. The reason for this request is because Flyout is a control much more effective than Popup. This one infact that requires much more effort in development because its positioning is totally in charge of the developer. With Flyout instead the positioning is handled by the control.</p> <p style="text-align: justify;">With XAML most of the work is conveniently done in C# also if you can create the popup in xaml. Here you create the Popup instance and then set the position and add some content. In the following snippet I add a Border element just only to make the popup visible. In a real world app, you probably create a user control to add to the popup. </p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Button_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Popup popup = <span style="color: #0000ff;">new</span> Popup();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> popup.IsLightDismissEnabled = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> popup.Child = <span style="color: #0000ff;">new</span> Border</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> Width = 200,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> Height = 200,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> Background = <span style="color: #0000ff;">new</span> SolidColorBrush(Colors.White),</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> BorderThickness = <span style="color: #0000ff;">new</span> Thickness(1)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> Button b = (Button)sender;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> var gt = b.TransformToVisual(<span style="color: #0000ff;">this</span>.root);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> Point offset = gt.TransformPoint(<span style="color: #0000ff;">new</span> Point(0, 0));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> popup.HorizontalOffset = offset.X;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> popup.VerticalOffset = offset.Y - 200 ;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> popup.IsOpen = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The position of the popup is calculated relatively to a positioned element in this case the button that caused its open. This code is for sure good to get a fine-tuned positioning but most of the times it is redundant and hard to be handled. In HTML the flyout control does most of the work for you.</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">button</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="action"</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="theButton"</span><span style="color: #0000ff;">></span>Click me!<span style="color: #0000ff;"></</span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="theFlyout"</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.Flyout"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>Do you confirm?<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">button</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="action"</span><span style="color: #0000ff;">></span>Yes!<span style="color: #0000ff;"></</span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This markup, placed into the page must be activated by code. So in Javascript you attach the button click event and you call the show method. This method requires two parameters, the control to be used to calculate the position and the relative placement, expressed with a string like "top", "bottom", etc...</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> ready: <span style="color: #0000ff;">function</span> (element, options)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">var</span> theButton = document.getElementById(<span style="color: #006080;">"theButton"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">var</span> theFlyout = document.getElementById(<span style="color: #006080;">"theFlyout"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> theButton.addEventListener(<span style="color: #006080;">"click"</span>,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">function</span>(ev)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> theFlyout.winControl.show(theButton, <span style="color: #006080;">"bottom"</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> }, <span style="color: #0000ff;">false</span>);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> },</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">So, if you are a XAML programmer you have two choices: if you are still on Windows 8 you can download "callisto" and you get a Flyout control very close to the WinJS one, or using Windows 8.1 you work with the new Flyout control. </p> <p style="text-align: justify;">Popup and Flyouts play an important role in Windows Store Apps, and they are used in a number of places. The most simple case is the confirmation popup that appear close to a button, but most of the times, AppBar commands are decorated with flyouts to tune functions and features. I'm pretty sure you found some of these popups in some apps. The important concept to have in mind is that a popup should be dismissed by simply clicking (or tap) outside of it. The is meaning of the IsLightDismissEnabled flag.</p> <h3 style="text-align: justify;">Context Menus</h3> <p style="text-align: justify;">The last surfaces that I would like to speak about are context menus. They are for sure a special case of flyouts but they are handled with a different control. In XAML and in HTML the control is exactly the same and it is called PopupMenu. The popup menu works as a set of UICommands, and the positioning is made relatively to another element like for Flyouts. Here is the C# code:</p> <div style="text-align: justify;"> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> async <span style="color: #0000ff;">void</span> TextBox_ContextMenuOpening(<span style="color: #0000ff;">object</span> sender, ContextMenuEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> e.Handled = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.LoremIpsum.SelectionLength > 0)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">string</span> first = <span style="color: #0000ff;">this</span>.LoremIpsum.SelectedText.Split(<span style="color: #006080;">' '</span>).FirstOrDefault();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> PopupMenu menu = <span style="color: #0000ff;">new</span> PopupMenu();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> menu.Commands.Add(<span style="color: #0000ff;">new</span> UICommand(first, <span style="color: #0000ff;">null</span>, 1));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> menu.Commands.Add(<span style="color: #0000ff;">new</span> UICommandSeparator());</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> menu.Commands.Add(<span style="color: #0000ff;">new</span> UICommand(<span style="color: #006080;">"To upper"</span>, <span style="color: #0000ff;">null</span>, 2));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> menu.Commands.Add(<span style="color: #0000ff;">new</span> UICommand(<span style="color: #006080;">"To lower"</span>, <span style="color: #0000ff;">null</span>, 3));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> IUICommand command = await menu.ShowForSelectionAsync(<span style="color: #0000ff;">this</span>.LoremIpsum.GetSelectionRect(), Placement.Below);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">if</span> (command != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;">switch</span> ((<span style="color: #0000ff;">int</span>)command.Id)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;">case</span> 1:</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;">break</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;">case</span> 2:</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;">this</span>.LoremIpsum.SelectedText = <span style="color: #0000ff;">this</span>.LoremIpsum.SelectedText.ToUpper();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;">break</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">case</span> 3:</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;">this</span>.LoremIpsum.SelectedText = <span style="color: #0000ff;">this</span>.LoremIpsum.SelectedText.ToLower();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> <span style="color: #0000ff;">break</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">In this example I open the popup close to the selection rectangle of a textbox with bottom placement. The code in Javascript is very similar because the control is part of Windows.UI.Popups instead of WinJS and is in common between both the languages. The calls differs only for name's capitalization.</p> <h3 style="text-align: justify;">Have surfaces under control</h3> <p style="text-align: justify;">Make a good usage of the available space in the windows Store apps is important to give an effective experience to your users. Togheter with the "surfaces" I've illustrated in this brief article you can count on multiple other solutions. The same Settings area is another surface to take in serious consideration for its purposes. My suggestion is to always plan carefully the elements, having clear in mind how the user must interact with the application to achieve the expected results.</p> http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Application-bars-flyouts-an-other-amenities.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Application-bars-flyouts-an-other-amenities.aspx#comments http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Application-bars-flyouts-an-other-amenities.aspx Thu, 18 Jul 2013 09:12:00 GMT Windows Store apps in HTML and XAML: Work with style(s) <table width="20"> <tbody> <tr> <td> <div data-layout="button_count" data-font="segoe ui" data-href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Work-with-style-s.aspx" data-send="false" data-show-faces="true" class="fb-like"></div> <br /> </td> <td><a data-url="http://slshow.net/15wD4td" data-text="#WindowsStore apps with #XAML & #HTML - Work with style(s). #win8dev #windows8" data-count="horizontal" data-counturl="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Work-with-style-s.aspx" data-via="silverlightshow" class="twitter-share-button" href="https://twitter.com/share">Tweet</a></td> <td><g:plusone href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Work-with-style-s.aspx" size="medium"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <p style="text-align: justify;">Up to here, I have always talked about XAML versus HTML and about C# versus Javascript, comparing features and functionalities. Working in the HTML side of the story, there is another actor of which we have to be aware of. It is the CSS stylesheet that is automatically created, as a common point to contain user interface aspects that apply to the whole application. </p> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Advanced-MVVM-concepts-using-Contoso-Cookbook-An-analysis-of-a-complete-MVVM-application-Part-1.aspx">Gill Cleeren's article series: Advanced MVVM concepts using Contoso Cookbook</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-LOB-Apps-with-Kona-Getting-Started.aspx">Brian Noyes' series: WinRT Business Apps with Prism</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx">Gill's ebook: Background processing in Windows 8</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_background.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/win8_background.png" alt="Background processing in Windows 8" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">It is a very common practice in HTML programming to set visual aspects of elements using a cascading style sheet and it is really important to centralize styles and make them much more maintainable. In my experience of trainer, moving to the XAML side of the story, the bad (but common) practice is to set properties directly on controls instead of creating styles. This comes probably from the use of tools that does not encourage the creation of styles but makes the "per-property approach" excessively easy. Styles are equally available in XAML and they are also slightly more powerful. In this article I would like to resume what it is a stylesheet and how is can be created in both HTML and XAML, to make it something of friendly.</p> <h3 style="text-align: justify;">Styles: how they work</h3> <p style="text-align: justify;">Cascading Style Sheets in HTML exist since long time. The current release of browsers supports the CSS 3.0 specifications that have added many features that make CSS really powerful and effective. Inside of Windows Store Apps, in the HTML programming, CSS are still present and they are based on the same 3.0 specification.</p> <p style="text-align: justify;">CSS and XAML's Styles are both a collection of properties, declared in the form of a series of name and values. These properties are applied to the element referred by the style. The main difference between xaml and html is that CSS works on a specific set of properties not related with HTML attributes but XAML styles are applied directly to the properties of XAML elements. This make xaml much more flexible because each new element, imported using the xaml extesibility can get a style applied on it.</p> <p style="text-align: justify;">As the name suggests, CSS are applied using a cascading logic that follows a well known prioritization logic, that applies as follow:</p> <p style="text-align: justify;"><span style="font-family: courier new;">style attribute > style tag > stylesheet files</span></p> <p style="text-align: justify;">This fallback chain states that, when you specify a style attribute directly on an element, it take priority over the one you specify inside a page using the <style> tag, and this take priority over the styles specified using a *.css file linked to the page. This precise fallback is really important because, thanks to its usage, it is really simple to create stylesheets that apply a common appearance to elements and that are overriden where it is required for some or all the aspects of the rule.</p> <p style="text-align: justify;">In XAML, styles also follows a similar chain of priority. They can be specified into the Resources section in the App.xaml or in every element in the Visual Tree with a Hierarchic model. When a Style is specified in a child it takes priority over the one that is defined on a parent element. And finally, the specification of an attribute has the highest priority overriding every style. </p> <p style="text-align: justify;">Additionally styles, both with HTML and XAML can be applied in various ways. They can be applied by classes, by element type and directly inline here is an example in HTML and XAML:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #cc6633;">.mybox</span> { <span style="color: #0000ff;">border</span>: <span style="color: #006080;">solid black 1px;</span> <span style="color: #0000ff;">background-color</span>: <span style="color: #006080;">red;</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">div</span> { <span style="color: #0000ff;">border</span>: <span style="color: #006080;">solid black 1px;</span> <span style="color: #0000ff;">background-color</span>: <span style="color: #006080;">red;</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #006080;"><</span><span style="color: #0000ff;">div</span> <span style="color: #0000ff;">style</span>="<span style="color: #0000ff;">border</span>: <span style="color: #006080;">solid black 1px;</span> <span style="color: #0000ff;">background-color</span>: <span style="color: #006080;">red;</span>" /<span style="color: #006080;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Here is the same in XAML</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="mybox"</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="Rectangle"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Stroke"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Black"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Fill"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Red"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="Rectangle"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Stroke"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Black"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Fill"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Red"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle.Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="Rectangle"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Stroke"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Black"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Fill"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Red"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Rectangle.Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Rectangle</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Both in CSS and in XAML the last syntax is strongly discouraged, because it strictly connect the style with the element and it is hard to be overriden. Using an external stylesheet instead, is a good practice for maintenability.</p> <p style="text-align: justify;">CSS have an additional way to be applied that is completely unknown to XAML. This is specifying an element name or, and this is the very power of CSS, using a selector that explores the DOM to reach the target element. There is a powerful syntax to query the DOM that is also used by tools like jQuery:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> #myboxname { <span style="color: #0000ff;">border</span>: <span style="color: #006080;">solid black 1px;</span> <span style="color: #0000ff;">background-color</span>: <span style="color: #006080;">red;</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">div</span>[data-role='item'] <span style="color: #006080;">></span> a:hover { <span style="color: #0000ff;">color</span>: <span style="color: #006080;">red;</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The last syntax is a CSS selector that reaches every <a> element, contained in a <div>, when it is hovered by the mouse. This let you specify different states for each element, in a way that xaml simply does not recognize.</p> <p style="text-align: justify;">The real power of xaml styles instead comes from some specific features: first of all, a style's property is strictly typed and is able to specify every type of dependency property, also if it contains a complex datatype. As an example a style can specify a full new template that is able to completely change the structure and behavior of a control, or define a default data template that applies to a specific styled ItemsControl, moving the structure of an item out of the pages's XAML file. </p> <p style="text-align: justify;">Another great feature of styles in XAML is inheritance. Thanks to the BasedOn attribute, which connects styles together, you can create a sort of chain where very common properties are expressed in base styles and they are inherited by more specific styles. In HTML css there is not a similar feature but you are able to specify multiple classes to the same element, separating it with spaces. It is not so friendly as the BasedOn attribute in XAML because you move it the html page, but is someway useful and commonly used: An example in XAML:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="BaseTextStyle"</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="TextBox"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="FontFamily"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Verdana"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="FontSize"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="12"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Foreground"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Black"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="AlertTextStyle"</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="TextBox"</span> <span style="color: #ff0000;">BasedOn</span><span style="color: #0000ff;">="{StaticResource BaseTextStyle}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Foreground"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Red"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="FontWeight"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">TextBlocks are a place where often the BasedOn attribute demontrates its usefulness. In this example, the BaseTextStyle centralizes the FontFamily specification and gives some default values for Foreground and FontSize. Each style inherits this specification and can override some or all of them. Let see something similar in CSS:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #006080;"><</span><span style="color: #0000ff;">style</span><span style="color: #006080;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #cc6633;">.baseTextStyle</span> { <span style="color: #0000ff;">font-family</span>: <span style="color: #006080;">verdana;</span> <span style="color: #0000ff;">font-size</span>: <span style="color: #006080;">12pt;</span> <span style="color: #0000ff;">color</span>: <span style="color: #006080;">#000;</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #cc6633;">.alert</span> { <span style="color: #0000ff;">color</span>: <span style="color: #006080;">#f00;</span> <span style="color: #0000ff;">font-weight</span>: <span style="color: #006080;">bold;</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #006080;"><</span><span style="color: #0000ff;">style</span><span style="color: #006080;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #006080;"><</span><span style="color: #0000ff;">div</span> class="baseTextStyle alert"<span style="color: #006080;">></span>My alert Text<span style="color: #006080;"><</span>/<span style="color: #0000ff;">div</span><span style="color: #006080;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">As you can see the connection between styles is made in HTML but with XAML it is made in the Style chain making it much more easy to maintain. Creation of theme thanks to this feature is straightforward.</p> <h3 style="text-align: justify;">Use styles for application theme</h3> <p style="text-align: justify;">After this short introduction to the connection point between CSS and Styles, let see how we can structure styles in an application to make it readable and maintainable. This is not a really easy task and usually they are required some practical tries to start understand the real power of styles and begin to understand what is good for styles and what is not. Generally speaking, my feel is that there's a complete set of properties that may be easily styled and where it makes really sense. There are also another set of properties that may be styled for default values but that tipically have their values customized page by page. this includes Width and Height that much of the times are strictly related with the content of the page and they are, much of the times, customized in-place. Differently, properties like colors, fonts, thickness, margins and padding, alignment and (in xaml) templates, have a great advantage in being applied by style. Speaking for XAML you usually work creating a base set of resources and then make it available to the application using a styles hierarchy using the BaseOn attribute. The most simple example is for colors:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Color</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="NormalColor"</span><span style="color: #0000ff;">></span>#FF333333<span style="color: #0000ff;"></</span><span style="color: #800000;">Color</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Color</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="MediumColor"</span><span style="color: #0000ff;">></span>#FF888888<span style="color: #0000ff;"></</span><span style="color: #800000;">Color</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Color</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="AlertColor"</span><span style="color: #0000ff;">></span>#FFFF0000<span style="color: #0000ff;"></</span><span style="color: #800000;">Color</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SolidColorBrush</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="NormalBrush"</span> <span style="color: #ff0000;">Color</span><span style="color: #0000ff;">="{StaticResource NormalColor}"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SolidColorBrush</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="MediumBrush"</span> <span style="color: #ff0000;">Color</span><span style="color: #0000ff;">="{StaticResource MediumColor}"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">SolidColorBrush</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="AlertBrush"</span> <span style="color: #ff0000;">Color</span><span style="color: #0000ff;">="{StaticResource AlertColor}"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">LinearGradientBrush</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="NormalToMediumBrush"</span> <span style="color: #ff0000;">StartPoint</span><span style="color: #0000ff;">="0,0"</span> <span style="color: #ff0000;">EndPoint</span><span style="color: #0000ff;">="1,0"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">GradientStop</span> <span style="color: #ff0000;">Color</span><span style="color: #0000ff;">="{StaticResource NormalColor}"</span> <span style="color: #ff0000;">Offset</span><span style="color: #0000ff;">="0"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">GradientStop</span> <span style="color: #ff0000;">Color</span><span style="color: #0000ff;">="{StaticResource MediumColor}"</span> <span style="color: #ff0000;">Offset</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">LinearGradientBrush</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">With this snippet I define a simple palette made of instances of the Color class. This is the sole point where hexadecimal values are expressed. Then a set of "Brushes" uses the palette's color to create Brush's instances that can be used from styles. Thank's to this initial setup you are able to change a color for all the application in a single point. Also, and this is the real power of this structure, you can easily swap from a Solid color to a Gradient, manipulating only the styles, because they are simply "Brush" instances that are usually used by element's properties. </p> <p style="text-align: justify;">In CSS there is not a straightforward solution that emulates this structure. With plain CSS you have to write colors (but also recurring fonts, sizes and so on...) again and again for each style class. Fortunately you can use "less" that is a language built on top of css that does something similar to Typescripf for Javascript. To have less in Visual Studio you must install ASP.NET and Web Tools 2012.2 Update (<a href="http://weblogs.asp.net/scottgu/archive/2013/02/18/announcing-release-of-asp-net-and-web-tools-2012-2-update.aspx)">http://weblogs.asp.net/scottgu/archive/2013/02/18/announcing-release-of-asp-net-and-web-tools-2012-2-update.aspx)</a>. then you can manually create a ".less" file in Windows Store Apps project and work as follow </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> @NormalColor: <span style="color: #006080;">#333333;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> @MediumColor: <span style="color: #006080;">#888888;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> @AlertColor: <span style="color: #006080;">#FF0000;</span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This three rows snippet does exacly the same as the previous XAML's styles does. It defines three variables where the color value is stored. Then you can use the variable name in place of the color in each style. The compiler does the magic converting it to the usual stylesheet. Unfortunately with CSS you cannot emulate the brush swapping. Infact CSS uses directly colors in styles and does not have a brush concept. </p> <p style="text-align: justify;">Now that the colors have been defined you can use them in styles. In this snippet I define a base style and the use it for application wide purposes and for specific styles: </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="BaseTextStyle"</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="TextBlock"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="FontFamily"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="Verdana"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Foreground"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="{StaticResource NormalBrush}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">x:Key</span><span style="color: #0000ff;">="AlertTextStyle"</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="TextBlock"</span> <span style="color: #ff0000;">BasedOn</span><span style="color: #0000ff;">="{StaticResource BaseTextStyle}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Setter</span> <span style="color: #ff0000;">Property</span><span style="color: #0000ff;">="Foreground"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="{StaticResource AlertBrush}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Style</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Style</span> <span style="color: #ff0000;">TargetType</span><span style="color: #0000ff;">="TextBlock"</span> <span style="color: #ff0000;">BasedOn</span><span style="color: #0000ff;">="{StaticResource BaseTextStyle}"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Firstly I define a "BaseTextStyle" with default font and foreground (its color is taken by the palette). Then I define an "AlertTextStyle" overriding the foreground property in red. Finally I also define an implicit style based on the BaseTextStyle. This one will not be used directly in code but should be directly applied by default to all the elements, thanks to the implicit style.</p> <p style="text-align: justify;">To get something similar in CSS you have to write this, in a LESS file: </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> @NormalColor: <span style="color: #006080;">#333333;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> @MediumColor: <span style="color: #006080;">#888888;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> @AlertColor: <span style="color: #006080;">#FF0000;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #cc6633;">.BaseTextStyle</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">font-family</span>: <span style="color: #006080;">Verdana;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">color</span>: <span style="color: #006080;">@NormalColor;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #cc6633;">.AlertTextStyle</span> <span style="color: #006080;">{</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> .BaseTextStyle;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">color</span>: @AlertColor</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;">p</span> <span style="color: #006080;">{</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> .BaseTextStyle;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The trick here is made using a LESS feature. You can cross reference styles and have the referenced style copied into the secondary. Then, just because duplicated definitions in css are handled with a "last wins" rule, you can redefine some properties easily. This snippet produces the following CSS output:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #cc6633;">.BaseTextStyle</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">font-family</span>: <span style="color: #006080;">Verdana;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">color</span>: <span style="color: #006080;">#333333;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #cc6633;">.AlertTextStyle</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;">font-family</span>: <span style="color: #006080;">Verdana;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">color</span>: <span style="color: #006080;">#333333;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">color</span>: <span style="color: #006080;">#ff0000;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">p</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;">font-family</span>: <span style="color: #006080;">Verdana;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">color</span>: <span style="color: #006080;">#333333;</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">Note the duplicate definition in "AlertTextStyle". Since the "color" attribute is defined twice, the "#ff0000" wins over the previous. Also note that the default text is applied to "P" element with the same syntax. </p> <h3 style="text-align: justify;">Always create pages with styles</h3> <p style="text-align: justify;">This article is really too short to completely describe the power of styles. However, I hope I gave you an idea of a good way to follow to create your next application. The benefit of organizing styles, both in HTML and in XAML are multiple, but the very first is to make them a common point to handle the application appearance, to easily accomodate your customer's requests.</p> http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Work-with-style-s.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Work-with-style-s.aspx#comments http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Work-with-style-s.aspx Mon, 15 Jul 2013 12:06:00 GMT Windows Store apps in HTML and XAML: Handle settings <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Handle-settings.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Handle-settings.aspx" data-count="horizontal" data-text="#WindowsStore apps with #XAML & #HTML - Handle settings. #win8dev #windows8" data-url="http://slshow.net/19NXuRg">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Handle-settings.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Background-processing-in-Windows-8-Part-1-How-Windows-8-applications-execute.aspx">Gill Cleeren's article series: Background processing in Win8</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/Windows-Store-LOB-Apps-with-Kona-Getting-Started.aspx">Brian Noyes' series: WinRT Business Apps with Prism</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_services.aspx">Gill's ebook: Connecting Windows 8 Apps with Services</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_services.aspx"><img usemap="#rade_img_map_1291385581316" src="http://www.silverlightshow.net/Storage/Ebooks/win8_services_cover.png" alt="Connecting Windows 8 apps with services" style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p style="text-align: justify;">Almost every application has some kind of settings that enable the user to customize his experience, tuning the application behavior to his preferences. This is an important matter and, also if often settings fall under a small set of known locations, at the first sight it is not easy to understand where they are for an untrained user. Tools->Options, Edit->Preferences, or some strange settings button that is presented somewhere in the user interface. These and other are common locations where we are use to see, a little bit after having installed a new software and we simply need to change a unit measure, a font size and something else. </p> <p style="text-align: justify;">With Windows 8 Store apps, they just simplified the user experience with settings, determining by guidelines a well-known position where these useful handles must be placed. Please note I used the term "must", underlining that this is not something under our choice, but a sort of pillar that is strictly required by Windows Store certification. So, every time you need to create a settings interface you have to rely on the right-placed flyout that is usually opened with the settings charm, or simply pressing CTRL+I (at least on my machine).</p> <h3 style="text-align: justify;">Not only for settings.</h3> <p style="text-align: justify;">If you have already used a Windows Store app, you are aware that the settings experience is not strictly related with settings only. Tipically the interaction with settings pane is a two-step experience. First you trigger the settings by using the charms. The system answer opening a side panel where you can choose between a number of items. When you make a choice, the flyout changes, showing the settings you can manipulate. Also from the developer side, implementing the settings imply to support these two steps. First you have to populate the item in the first view, attaching a number of items. Then, answering to the click of one of these items you have to present the settings panel of do whatever you need to do related to the user choice. </p> <p style="text-align: justify;">As a matter of facts, the first panel not only contains the access to settings groups, but it is done also to hook up information about the application. Legal notices, privacy policies, about box and web site, contacts and support links. All these item must but set in the settings pane. </p> <p style="text-align: justify;">In this first part, the developer experience for html and xaml programmers is similar. The trick is made attaching an event that is raised when the user asks to open the panel with the settings charm. This event require you to pass a list of actions that becomes links. Here is the XAML code and then the HTML example:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">sealed</span> <span style="color: #0000ff;">partial</span> <span style="color: #0000ff;">class</span> App : Application</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">bool</span> hasSettings = <span style="color: #0000ff;">false</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnWindowCreated(WindowCreatedEventArgs args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">this</span>.hasSettings)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> SettingsPane.GetForCurrentView().CommandsRequested += Settings_CommandsRequested;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">this</span>.hasSettings = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Settings_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> SettingsCommand aboutCommand = <span style="color: #0000ff;">new</span> SettingsCommand(<span style="color: #006080;">"aboutId"</span>, <span style="color: #006080;">"About"</span>, HandleSettingsClick);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> args.Request.ApplicationCommands.Add(aboutCommand);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> SettingsCommand helpCommand = <span style="color: #0000ff;">new</span> SettingsCommand(<span style="color: #006080;">"helpId"</span>, <span style="color: #006080;">"Help"</span>, HandleSettingsClick);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> args.Request.ApplicationCommands.Add(helpCommand);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> SettingsCommand settingsCommand = <span style="color: #0000ff;">new</span> SettingsCommand(<span style="color: #006080;">"settingsId"</span>, <span style="color: #006080;">"Settings"</span>, HandleSettingsClick);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> args.Request.ApplicationCommands.Add(settingsCommand);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> HandleSettingsClick(IUICommand command)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">This code placed in the Application startup handles the moment when the window is created. This let the setting to be in place every time when the application is started for some reason. In the OnWindowCreated method I use a bool flag to avoid duplicated hook that may happen. When the event is raised, a number of SettingsCommand are created and added to the receiver EventArg. This event is raised a bit after the user asked for the settings panel. In HTML the things appear pretty similar:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">// this goes in default.js</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> WinJS.Application.onsettings = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> function (e) </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> e.detail.applicationcommands =</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #006080;">"aboutId"</span>: { title: <span style="color: #006080;">"About"</span>, href: <span style="color: #006080;">"/html/Help.html"</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #006080;">"helpId"</span>: { title: <span style="color: #006080;">"Help"</span>, href: <span style="color: #006080;">"/html/About.html"</span> },</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #006080;">"settingsId"</span>: { title: <span style="color: #006080;">"Setting"</span>, href: <span style="color: #006080;">"/html/Settings.html"</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> WinJS.UI.SettingsFlyout.populateSettings(e);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span>  </pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The important thing in this declaration is the identifier given to the command. This is double true in Javascript and HTML because it automatically hooks up the html fragment to be displayed in the settings pane. In XAML instead this identifier is useful but the developer gets the entire IUICommand instance and is also able to attach a different event to each command. </p> <p style="text-align: justify;">If you need, in Javascript you can also attach the event handler to the command button. This is useful if you need to start an external link. To do this the syntax is slightly different:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">// this goes in default.js</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> WinJS.Application.onsettings = </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">function</span> (e) </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> e.detail.e.request.applicationCommands.append(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">new</span> Windows.UI.ApplicationSettings.SettingsCommand(<span style="color: #006080;">"privacyId"</span>, <span style="color: #006080;">"Privacy Policy"</span>, </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">function</span>() </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #008000;">// do what you want when clicked!</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }));</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> WinJS.UI.SettingsFlyout.populateSettings(e);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> };</pre> <!--CRLF--></div> </div> </div> <h3 style="text-align: justify;">Displaying the settings</h3> <p style="text-align: justify;">After loading the choices, you may expect the user hits one of your links. This lead to a number of actions. In the most simple case you open an external browser to display a web page, as in the case of privacy policies or credits. But when the user asks for internal application settings, these must be displayed into your app following some simple rules. The opened panel may have two sizes: 346 pixels in the normal case and 646 when it is extended. The panel must reside on the right side as usual and it should have a back button, in the left top corner, to return to the previous pane. </p> <p style="text-align: justify;">Working with XAML this operation requires some more work than in HTML. This because in HTML the system automatically handle to construction and position of the settings panel but in XAML you are in charge of doing this operation. So in XAML, when in the setting command handler you have first to create a Popup instance and place it on the right side. </p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Settings_CommandsRequested(IUICommand command)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Rect boundaries = Window.Current.Bounds;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">double</span> settingsWidth = 646d;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> thePopup = <span style="color: #0000ff;">new</span> Popup();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> thePopup.Closed += HandlePopupClosed;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Window.Current.Activated += HandleWindowActivated;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> thePopup.IsLightDismissEnabled = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> thePopup.Width = settingsWidth;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> thePopup.Height = boundaries.Height;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #008000;">// Add the proper animation for the panel.</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> thePopup.ChildTransitions = <span style="color: #0000ff;">new</span> TransitionCollection</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;">new</span> PaneThemeTransition() </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> { </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> Edge = (SettingsPane.Edge == SettingsEdgeLocation.Right) ? EdgeTransitionLocation.Right : EdgeTransitionLocation.Left</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #008000;">// Create a SettingsFlyout the same dimenssions as the Popup.</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> SettingsFlyout mySettingsControl = <span style="color: #0000ff;">new</span> SettingsFlyout</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> Width = settingsWidth,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> Height = boundaries.Height</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> };</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #008000;">// Place the SettingsFlyout inside our Popup window.</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> thePopup.Child = mySettingsControl;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> Canvas.SetLeft(thePopup, SettingsPane.Edge == SettingsEdgeLocation.Right ? (boundaries.Width - settingsWidth) : 0);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum33" style="color: #606060;"> 33:</span> Canvas.SetTop(thePopup, 0);</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum34" style="color: #606060;"> 34:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum35" style="color: #606060;"> 35:</span> thePopup.IsOpen = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum36" style="color: #606060;"> 36:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum37" style="color: #606060;"> 37:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum38" style="color: #606060;"> 38:</span> <span style="color: #0000ff;">void</span> HandlePopupClosed(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum39" style="color: #606060;"> 39:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum40" style="color: #606060;"> 40:</span> thePopup.Closed -= HandlePopupClosed;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum41" style="color: #606060;"> 41:</span> Window.Current.Activated -= HandleWindowActivated;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum42" style="color: #606060;"> 42:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum43" style="color: #606060;"> 43:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum44" style="color: #606060;"> 44:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> HandleWindowActivated(<span style="color: #0000ff;">object</span> sender, Windows.UI.Core.WindowActivatedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum45" style="color: #606060;"> 45:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum46" style="color: #606060;"> 46:</span> <span style="color: #0000ff;">if</span> (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum47" style="color: #606060;"> 47:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum48" style="color: #606060;"> 48:</span> thePopup.IsOpen = <span style="color: #0000ff;">false</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum49" style="color: #606060;"> 49:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum50" style="color: #606060;"> 50:</span> }</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">As you can see, positioning the flyout is matter of measuring the available space and tuning the size. The horizontal size is fixed (in this case 646pixel) but the vertical size is based on the windows boundaries. You have also to connect the dismiss events to close the popup when the user clicks away.  In HTML you only have to correctly refer to an application command id:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><!</span><span style="color: #800000;">doctype</span> <span style="color: #ff0000;">HTML</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></span>App settings flyout<span style="color: #0000ff;"></</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">script</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">="/js/Settings.js"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">script</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #008000;"><!-- BEGIN --></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.SettingsFlyout"</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="programmaticInvocationSettingsFlyout"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #ff0000;">aria-label</span><span style="color: #0000ff;">="App Settings Flyout"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{settingsCommandId:'settingsId', width:'wide'}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="win-ui-dark win-header"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">button</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">="button"</span> <span style="color: #ff0000;">onclick</span><span style="color: #0000ff;">="WinJS.UI.SettingsFlyout.show()"</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="win-backbutton"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">button</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="win-label"</span><span style="color: #0000ff;">></span>Settings<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="win-content"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="win-settings-section"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">h3</span><span style="color: #0000ff;">></span>GPS tracking<span style="color: #0000ff;"></</span><span style="color: #800000;">h3</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">p</span><span style="color: #0000ff;">></span>Setup GPS tracking options.<span style="color: #0000ff;"></</span><span style="color: #800000;">p</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">data-win-control</span><span style="color: #0000ff;">="WinJS.UI.ToggleSwitch"</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #ff0000;">data-win-options</span><span style="color: #0000ff;">="{title:'Enable Continuous tracking', checked:true}"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #008000;"><!-- END --></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum31" style="color: #606060;"> 31:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum32" style="color: #606060;"> 32:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">In this file, it is set the data-win-options attribute with the correct settingsCommandId. This suffice because the runtime understand that it has to load the page and display it into the right placed popup. You are in charge of positioning the back button and, into the onclick event, calling the "WinJS.UI.SettingsFlyout.show()" method to dismiss the flyout. In XAML you have to create also the settings control, usually an UserControl:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Border</span> <span style="color: #ff0000;">BorderBrush</span><span style="color: #0000ff;">="#00b2f0"</span> <span style="color: #ff0000;">BorderThickness</span><span style="color: #0000ff;">="1,0,0,0"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="White"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Stretch"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.RowDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="80"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">RowDefinition</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="*"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.RowDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span> <span style="color: #ff0000;">Background</span><span style="color: #0000ff;">="#00b2f0"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="0"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ColumnDefinition</span> <span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="*"</span> <span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Orientation</span><span style="color: #0000ff;">="Horizontal"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Column</span><span style="color: #0000ff;">="0"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="40, 32, 17, 13"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">Click</span><span style="color: #0000ff;">="MySettingsBackClicked"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,3,0,0"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource SettingsBackButtonStyle}"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="10,0,0,0"</span> <span style="color: #ff0000;">FontFamily</span><span style="color: #0000ff;">="Segoe UI"</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="SemiLight"</span> <span style="color: #ff0000;">FontSize</span><span style="color: #0000ff;">="24.6667"</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Defaults"</span> <span style="color: #ff0000;">Foreground</span><span style="color: #0000ff;">="White"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ScrollViewer</span> <span style="color: #ff0000;">VerticalScrollBarVisibility</span><span style="color: #0000ff;">="Auto"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">Row</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">Grid</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="40,33,40,39"</span> <span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Top"</span> <span style="color: #ff0000;">Grid</span>.<span style="color: #ff0000;">RowSpan</span><span style="color: #0000ff;">="3"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="FlyoutContent"</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="GPS tracking"</span> <span style="color: #ff0000;">TextWrapping</span><span style="color: #0000ff;">="Wrap"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource BasicTextStyle}"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Setup GPS tracking options."</span> <span style="color: #ff0000;">TextWrapping</span><span style="color: #0000ff;">="Wrap"</span> <span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{StaticResource BasicTextStyle}"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">ToggleSwitch</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="-6,25, 0, 0"</span> <span style="color: #ff0000;">Header</span> = <span style="color: #0000ff;">"Enable Continuous tracking"</span> <span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span> <span style="color: #ff0000;">HorizontalContentAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #0000ff;">/></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">ScrollViewer</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Grid</span><span style="color: #0000ff;">></span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">Border</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">In the codebehind the code to dismiss the pane is this:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> MySettingsBackClicked(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> Popup parent = <span style="color: #0000ff;">this</span>.Parent <span style="color: #0000ff;">as</span> Popup;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">if</span> (parent != <span style="color: #0000ff;">null</span>)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> parent.IsOpen = <span style="color: #0000ff;">false</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #0000ff;">if</span> (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> SettingsPane.Show();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> }</pre> <!--CRLF--></div> </div> </div> <h3 style="text-align: justify;">Programmatically open the pane.</h3> <p style="text-align: justify;">Also if charms is the required access point to the settings pane, you can also allow another way to pop up the same pane. This is enabled calling a method thaat invokes the pane and opens it. Here is how call the method in C# and Javascript:</p> <div style="text-align: justify;"> <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: "courier new",courier,monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;"> <div id="codeSnippet" style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">// in C# </span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> SettingsPane.Show();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #008000;">// in Javascript</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: "courier new",courier,monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> WinJS.UI.SettingsFlyout.showSettings(<span style="color: #006080;">"settingsId"</span>, <span style="color: #006080;">"/html/Settings.html"</span>);</pre> <!--CRLF--></div> </div> </div> <p style="text-align: justify;">The slight difference is that in Javascript you can specify the settings page to load but in C# this is not availale. You can only open the setting page and then the user have to select the command to navigate.</p> http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Handle-settings.aspx editorial@silverlightshow.net (Andrea Boschin ) http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Handle-settings.aspx#comments http://www.silverlightshow.net/items/Windows-Store-apps-in-HTML-and-XAML-Handle-settings.aspx Mon, 01 Jul 2013 12:01:00 GMT Background processing in Windows 8: Part 6: Playing audio in the background <table width="20"> <tbody> <tr> <td> <div class="fb-like" data-show-faces="true" data-send="false" data-href="http://www.silverlightshow.net/items/Background-processing-in-Windows-8-Part-6-Playing-audio-in-the-background.aspx" data-font="segoe ui" data-layout="button_count"></div> <br /> </td> <td><a href="https://twitter.com/share" class="twitter-share-button" data-via="silverlightshow" data-counturl="http://www.silverlightshow.net/items/Background-processing-in-Windows-8-Part-6-Playing-audio-in-the-background.aspx" data-count="horizontal" data-text="'Background processing in #Win8: Playing audio in the background' via @gillcleeren #win8dev" data-url="http://slshow.net/14g2VFc">Tweet</a></td> <td><g:plusone size="medium" href="http://www.silverlightshow.net/items/Background-processing-in-Windows-8-Part-6-Playing-audio-in-the-background.aspx"></g:plusone> <br /> </td> <td> <br /> </td> </tr> </tbody> </table> <div style="border: 1px solid #dddddd; background-color: #f3f3f3; margin-top: 5px; margin-left: 150px; padding-left: 10px; padding-top: 10px; width: 400px; text-align: center;"><strong><a href="http://www.silverlightshow.net/Storage/Sources/Source_Win8_Demos_Part6.zip">Download the source code for this article</a></strong> </div> <p>It’s that time again… We’ve reached the last part of this article series on background processing in Windows 8. So almost time to say goodbye for now! </p> <p>But we’re not there yet. In the previous module, we’ve covered background downloads. We’ve seen that to enable these, we need to use a separate service that keeps transferrin our files when we’re not actively using the application (in other words, have it open as the main app on screen). But what if we want to have an app that plays audio such as Media Player? We probably want to create such an app so that it plays audio when we’re using the app but also so that it continues playing our content when we’re doing something else. Otherwise, we’d simply be changing our tablet in a media player which doesn’t allow me to do any other task while I’m playing music in the background. Again, that’s not a good experience, that’s not what a user wants. </p> <p>In this article, we’ll explore the way we want play audio while the audio player app isn’t in the foreground.</p> <h4>The good old MediaElement</h4> <div style="border: 1px solid #dddddd; padding-bottom: 5px; background-color: #f3f3f3; margin-top: 5px; padding-left: 10px; width: 200px; float: right; margin-left: 10px; padding-top: 5px;"> <h3>Don't miss</h3> <ul style="list-style-type: circle; margin: 0px; padding-left: 20px; font-size: 12px;"> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/video/Working-in-the-background-in-Win8-Webinar.aspx">Recording of Gill's webinar: Working in the background in Win8</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/items/MVVM-in-Windows-8-Part-1.aspx">3-part article series: MVVM in Windows 8</a> </li> <li style="padding-bottom: 5px;"><a href="http://www.silverlightshow.net/ebooks/win8_services.aspx">Gill's ebook: Connecting Windows 8 Apps with Services</a></li> </ul> <p style="padding-bottom: 5px; text-align: center;"><a href="http://www.silverlightshow.net/ebooks/win8_services.aspx"><img style="width: 80px; height: 113px; border-width: 0px; border-style: solid;" alt="Connecting Windows 8 apps with services" src="http://www.silverlightshow.net/Storage/Ebooks/win8_services_cover.png" usemap="#rade_img_map_1291385581316" /></a></p> <p style="font-size: 12px;">     <a href="http://www.silverlightshow.net/ebooks.aspx">All SilverlightShow Ebooks</a> <img alt="" src="http://www.silverlightshow.net/Storage/arrow-content.jpg" /></p> </div> <p>In Silverlight and other XAML-based technologies, we’ve used the MediaElement control for most of our media needs. The control is smart enough to know that if you’re giving it an audio (for example an MP3 file), it’s being used for audio and if you pass it a movie file (like a WMV file), it’ll need to visibly show that movie.</p> <p>The control behaves pretty much the same in Windows 8. It can handle most media types. But there’s one thing that bothers us: if we have a MediaElement in our app, we might want to have at least the option that the media continues playing even if the app is not in the foreground any more. By default, the behaviour is such that as soon as the app gets suspended (which is 5 seconds after not being the main app on screen any more), the MediaElement will stop playing the content. If you think about this, this is pretty logical, as no code can execute once the app gets suspended (including code that needs to run to play the media). So indeed, building a Spotify client or basically any media app is pretty much impossible, as the user will need to keep the app open (at least in snap view).</p> <p>Another scenario that’s going to be problematic is background audio communications. Think of a Skype-like application that can only allow us to talk with someone when we have the app open. This wouldn’t be a good experience at all! It would be for example impossible to search some info on the web while we’re having a call with someone. Impossible to imagine in 2013, isn’t it?!</p> <p>It turns out though that an extra property was added on the MediaElement class in Windows 8 namely the AudioCategory property. This property is of type AudioCategory (they weren’t being very original with the names that day!) and that is an enumeration that can have a couple of values. This enumeration is shown in the code below. </p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">enum</span> AudioCategory</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> Other = 0,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> ForegroundOnlyMedia = 1,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> BackgroundCapableMedia = 2,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> Communications = 3,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Alerts = 4,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> SoundEffects = 5,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> GameEffects = 6,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> GameMedia = 7,</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> }</pre> <!--CRLF--></div> </div> <p>There are 2 important values in this enumeration that will enable us to use the MediaElement in the two scenarios described above, namely the BackgroundCapableMedia and Communications. The first one is useful for media player while the second one will be useful in the communication-scenario such as Skype.</p> <p>Let’s now look at creating a background-capable media player app.</p> <h4>Creating a background-enabled audio player</h4> <p>To create this type of media player app, we have to specify in the app manifest this type of background task. As can be seen below, the app has a background task declaration and the supported type is set to Audio. There’s no real background code required here (as we’ve seen with the background tasks), so we don’t have to specify the Entry Point. </p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_______clip_image002_2.jpg"><img width="394" height="225" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_______clip_image002_thumb.jpg" alt="clip_image002" style="display: inline; background-image: none; border-width: 0px; border-style: solid;" title="clip_image002" /></a></p> <p>Next, as mentioned, we need to use a MediaElement in which we are specifying the value of the AudioCategory property to BackgroundCapableMedia. </p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">MediaElement</span> <span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="BackgroundEnabledMediaElement"</span> <span style="color: #ff0000;">AudioCategory</span><span style="color: #0000ff;">="BackgroundCapableMedia"</span> <span style="color: #ff0000;">AutoPlay</span><span style="color: #0000ff;">="False"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">MediaElement</span><span style="color: #0000ff;">></span></pre> <!--CRLF--></div> </div> <p>If we run the app now with just these 2 options set, things won’t work yet though. The audio will only play when the app is the main app on screen. It’s required that we add some more code: we need to register for a couple of MediaControl events. The MediaControl is the little thing in Windows 8 that allows you to change the volume and the playing song as shown below.</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image003_2.png"><img width="289" height="283" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/____clip_image003_thumb.png" alt="clip_image003" style="display: inline; background-image: none; border-width: 0px; border-style: solid;" title="clip_image003" /></a></p> <p>We need to register for the following events:</p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> MediaControl.PlayPressed += MediaControl_PlayPressed;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> MediaControl.StopPressed += MediaControl_StopPressed;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> MediaControl.PausePressed += MediaControl_PausePressed;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed;</pre> <!--CRLF--></div> </div> <p>We can then handle these events as follows:</p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> async <span style="color: #0000ff;">void</span> MediaControl_PlayPressed(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> BackgroundEnabledMediaElement.Play();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> MediaControl.IsPlaying = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> }</pre> <!--CRLF--></div> </div> <p>In the code above, we handle that the Play button in the on-screen controls was clicked. We call on to the MediaElement of our app to start playing and change the state of the MediaControl itself (so it too can update its state).</p> <p>This code is different from the actual, typical PlayButton Click code, which is shown below.</p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> PlayButton_Click_1(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> MediaControl.IsPlaying = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> BackgroundEnabledMediaElement.Play();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> MediaControl.TrackName = selectedFile.Name;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> }</pre> <!--CRLF--></div> </div> <p>In this code, we do more or less the same, however, this code simple executes on the main UI thread, whereas we had to use the Dispatcher before to get access to the UI element (hence the code ran on a background thread).</p> <p>In the PlayPauseTogglePressed, we add the following code:</p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> async <span style="color: #0000ff;">void</span> MediaControl_PlayPauseTogglePressed(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">try</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">if</span> (BackgroundEnabledMediaElement.CurrentState == MediaElementState.Paused)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> BackgroundEnabledMediaElement.Play();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> MediaControl.IsPlaying = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">else</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> BackgroundEnabledMediaElement.Pause();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> MediaControl.IsPlaying = <span style="color: #0000ff;">false</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">catch</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> }</pre> <!--CRLF--></div> </div> <p>Here we first check if the current state is already playing and if so, we pause, otherwise we start the playback. This code too doesn’t run on the UI thread, since it will be called from the MediaControl (and it’s possible that the app has no UI visible at this time).</p> <p>The net result is the following:</p> <p><a href="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image004_2.png"><img width="244" height="54" src="http://www.silverlightshow.net/Storage/Users/gillcleeren/_____clip_image004_thumb.png" alt="clip_image004" style="display: inline; background-image: none; border-width: 0px; border-style: solid;" title="clip_image004" /></a>As you can see, the media player app is not being suspended when it’s playing audio on my system. We have successfully created a background-enabled audio player. </p> <p>There’s one more thing to add!</p> <h4>Adding support for the SoundLevelChanged event</h4> <p>The SoundLevelChanged event is an event that will fire when your application is currently playing audio and another app wants to play audio as well. It turns out that of course only having one app that plays audio at the same time is beneficial, so the event will fire and allow us to react to what we want to do when some other app wants to playback audio. For example, if you’re getting an incoming phone call on Skype and your app is still playing audio, this event will fire.</p> <p>Registering for this event is done on the MediaControl:</p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> MediaControl.SoundLevelChanged += MediaControl_SoundLevelChanged;</pre> <!--CRLF--></div> </div> <p>The code below handles this event:</p> <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; line-height: 12pt; overflow: auto; font-family: 'courier new', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4; text-align: left;" id="codeSnippetWrapper"> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4; text-align: left;" id="codeSnippet"> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> async <span style="color: #0000ff;">void</span> MediaControl_SoundLevelChanged(<span style="color: #0000ff;">object</span> sender, <span style="color: #0000ff;">object</span> e)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span> var currentSoundLevel = MediaControl.SoundLevel;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>  </pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">if</span> (currentSoundLevel == SoundLevel.Muted)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span> await coreWindow.Dispatcher.RunAsync(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span> Windows.UI.Core.CoreDispatcherPriority.Normal, () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #0000ff;">if</span> (BackgroundEnabledMediaElement.CurrentState !=</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span> MediaElementState.Paused)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span> BackgroundEnabledMediaElement.Pause();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum14" style="color: #606060;"> 14:</span> MediaControl.IsPlaying = <span style="color: #0000ff;">false</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: #606060;"> 15:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum16" style="color: #606060;"> 16:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: #606060;"> 17:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum18" style="color: #606060;"> 18:</span> <span style="color: #0000ff;">else</span></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: #606060;"> 19:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum20" style="color: #606060;"> 20:</span> await coreWindow.Dispatcher.RunAsync(</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: #606060;"> 21:</span> Windows.UI.Core.CoreDispatcherPriority.Normal, () =></pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum22" style="color: #606060;"> 22:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: #606060;"> 23:</span> <span style="color: #0000ff;">if</span> (BackgroundEnabledMediaElement.CurrentState != MediaElementState.Playing)</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum24" style="color: #606060;"> 24:</span> {</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: #606060;"> 25:</span> BackgroundEnabledMediaElement.Play();</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum26" style="color: #606060;"> 26:</span> MediaControl.IsPlaying = <span style="color: #0000ff;">true</span>;</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: #606060;"> 27:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum28" style="color: #606060;"> 28:</span> });</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: #606060;"> 29:</span> }</pre> <!--CRLF--> <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'courier new', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum30" style="color: #606060;"> 30:</span> }</pre> <!--CRLF--></div> </div> <p>If the “incoming” sound level is muted (meaning another app needs to use the sound channel, so our app is being muted), we can pause the playback so that when the user is finished making the phone call, he can resume the song afterwards.</p> <p>With this, we have finished our media player app!</p> <h4>Summary</h4> <p>In this 6<sup>th</sup> and last part of this series, we have looked at how we can create apps that play audio in the background. We’ve seen that by using the AudioCategory property on the MediaElement, we can change the app so that it’s not being suspended and can thus continue playing audio.</p> <h4>Series Summary</h4> <p>With this 6<sup>th</sup> part finished, this series is finished as well. We have covered a lot of ground and hopefully you’ve understood now how processes in the background in Windows 8 work. While being very constrained, a good deal of options exists to perform work in the background in Windows 8. It’s going to be interesting to see if Microsoft will add any changes to all this in the upcoming preview of Windows 8.1. We’ll surely cover the changes here at SilverlightShow as well.</p> <p>If you want to learn even more on background processing, you can take a look at my Pluralsight course on this topic. It of course digs a lot deeper in many of the topics we’ve seen in this series. You can take a look at this course here: <a href="http://pluralsight.com/training/Courses/TableOfContents/win8-bgproc">http://pluralsight.com/training/Courses/TableOfContents/win8-bgproc</a>.</p> <h4>About the author</h4> <p>Gill Cleeren is Microsoft Regional Director, Silverlight MVP, Pluralsight trainer and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina. Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd, TechDays, DevDays, NDC Oslo, SQL Server Saturday Switserland, Silverlight Roadshow in Sweden, Telerik RoadShow UK… Gill has written 2 books: “Silverlight 4 Data and Services Cookbook” and Silverlight 5 Data and Services Cookbook and is author of many articles for magazines and websites. You can find his blog at www.snowball.be. Twitter: @gillcleeren</p> http://www.silverlightshow.net/items/Background-processing-in-Windows-8-Part-6-Playing-audio-in-the-background.aspx editorial@silverlightshow.net (Gill Cleeren ) http://www.silverlightshow.net/items/Background-processing-in-Windows-8-Part-6-Playing-audio-in-the-background.aspx#comments http://www.silverlightshow.net/items/Background-processing-in-Windows-8-Part-6-Playing-audio-in-the-background.aspx Tue, 18 Jun 2013 13:19:00 GMT