<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Amar's blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/amar/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/amar/feed.xml</link>
    <description>My learnings, my perspective.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:13:08 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Show file thumbnails in your Windows Store App</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/show-file-thumbnails-in-your-windows-store-app</link>
      <pubDate>Wed, 14 Jan 2015 00:21:04 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2015/01/14/show-file-thumbnails-in-your-windows-store-app/</guid>
      <description><![CDATA[&nbsp; If your app has a requirement where you use a filepicker and then show the files that the...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p> <p>If your app has a requirement where you use a filepicker and then show the files that the user selects as a preview/list, chances are you would like the option to show thumbnails of the files.</p> <p>A quick search tells you that the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.getthumbnailasync.aspx">Windows.Storage.StorageFile.GetThumbnailAsync</a> is the way to go! However, I didn’t find an article which just put things together, so here you go <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0268.wlEmoticon-smile_24C77E78.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0268.wlEmoticon_2D00_smile_5F00_24C77E78.png"></p> <p>First things first - here are the screenshots from the sample app I wrote:</p> <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5808.clip_image002_38E09B01.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5808.clip_5F00_image002_5F00_38E09B01.jpg"><img title="clip_image002" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6825.clip_image002_thumb_08B9503E.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6825.clip_5F00_image002_5F00_thumb_5F00_08B9503E.jpg" width="804" height="453"></a>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5270.clip_image004_43A08307.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5270.clip_5F00_image004_5F00_43A08307.jpg"><img title="clip_image004" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image004" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5314.clip_image004_thumb_41668AFC.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5314.clip_5F00_image004_5F00_thumb_5F00_41668AFC.jpg" width="804" height="453"></a>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4667.clip_image006_2A3B107E.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4667.clip_5F00_image006_5F00_2A3B107E.jpg"><img title="clip_image006" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image006" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8308.clip_image006_thumb_3734F08F.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8308.clip_5F00_image006_5F00_thumb_5F00_3734F08F.jpg" width="804" height="453"></a>  <p>If this is not what you’re looking for, you may want to avoid reading the rest of this post - no hard feelings! <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0268.wlEmoticon-smile_24C77E78.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0268.wlEmoticon_2D00_smile_5F00_24C77E78.png"></p> <p>If this is what you were looking for, let’s get down to business!</p> <h5>1. Set up the FileOpenPicker, get selected files, get thumbnails of the selected files</h5> <div class="csharpcode"><pre class="alt"><span class="kwrd">private</span> async <span class="kwrd">void</span> ButtonBase_OnClick(<span class="kwrd">object</span> sender, RoutedEventArgs e)</pre><pre>{</pre><pre class="alt">    <span class="rem">// 1. Get FileOpenPicker ready</span></pre><pre>    var picker = <span class="kwrd">new</span> FileOpenPicker();</pre><pre class="alt">    picker.ViewMode = PickerViewMode.Thumbnail;</pre><pre>    picker.SuggestedStartLocation = PickerLocationId.ComputerFolder;</pre><pre class="alt">            </pre><pre>    <span class="rem">// 2. Add filters - it's required to have at least one filter</span></pre><pre class="alt">    <span class="rem">//    it CANNOT be a wildcard (i.e., no .*)</span></pre><pre>    picker.FileTypeFilter.Add(<span class="str">".docx"</span>);</pre><pre class="alt">    picker.FileTypeFilter.Add(<span class="str">".pptx"</span>);</pre><pre>    picker.FileTypeFilter.Add(<span class="str">".xlsx"</span>);</pre><pre class="alt">    picker.FileTypeFilter.Add(<span class="str">".xls"</span>);</pre><pre>    picker.FileTypeFilter.Add(<span class="str">".jpg"</span>);</pre><pre class="alt">    picker.FileTypeFilter.Add(<span class="str">".png"</span>);</pre><pre>    picker.FileTypeFilter.Add(<span class="str">".pdf"</span>);</pre><pre class="alt">&nbsp;</pre><pre>    <span class="rem">// 3. Call the file picker</span></pre><pre class="alt">    var file = await picker.PickMultipleFilesAsync();</pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">if</span> (file != <span class="kwrd">null</span>)</pre><pre>    {</pre><pre class="alt">        <span class="kwrd">foreach</span> (var storageFile <span class="kwrd">in</span> file)</pre><pre>        {</pre><pre class="alt">            <span class="rem">// fileList = new ObservableCollection&lt;SimpleFileInfo&gt;(); in the constructor</span></pre><pre>            <span class="rem">// SimpleFileInfo is a class with a string FileName and a StorageItemThumbnail Thumbnail field.</span></pre><pre class="alt">            fileList.Add(<span class="kwrd">new</span> SimpleFileInfo</pre><pre>            {</pre><pre class="alt">                FileName = storageFile.Name,</pre><pre>                <span class="rem">// 4. Get image thumbnails!!</span></pre><pre class="alt">                Thumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem)</pre><pre>            });</pre><pre class="alt">        }</pre><pre>                </pre><pre class="alt">    }</pre><pre>}</pre></div>


<h5>&nbsp;</h5>
<h5>2. Create a converter which converts StorageItemThumbnail to an Image</h5>
<p>The following snippet was used from Mike Taulty’s blog post on <a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2013/01/25/windows-8-making-a-simple-photo-viewer-in-c-and-xaml.aspx">Making a Simple Photo Viewer in C# and XAML</a>.</p>
<div class="csharpcode">
<div class="csharpcode"><pre class="alt"><span class="kwrd">using</span> Windows.Storage.FileProperties;</pre><pre><span class="kwrd">using</span> Windows.UI.Xaml.Data;</pre><pre class="alt"><span class="kwrd">using</span> Windows.UI.Xaml.Media;</pre><pre><span class="kwrd">using</span> Windows.UI.Xaml.Media.Imaging;</pre><pre class="alt">&nbsp;</pre><pre><span class="kwrd">public</span> <span class="kwrd">class</span> ThumbnailToImageConverter : IValueConverter</pre><pre class="alt">{</pre><pre>    <span class="kwrd">public</span> <span class="kwrd">object</span> Convert(<span class="kwrd">object</span> <span class="kwrd">value</span>, Type targetType, <span class="kwrd">object</span> parameter, <span class="kwrd">string</span> language)</pre><pre class="alt">    {</pre><pre>        BitmapImage image = <span class="kwrd">null</span>;</pre><pre class="alt">&nbsp;</pre><pre>        <span class="kwrd">if</span> (<span class="kwrd">value</span> != <span class="kwrd">null</span>)</pre><pre class="alt">        {</pre><pre>            <span class="kwrd">if</span> (<span class="kwrd">value</span>.GetType() != <span class="kwrd">typeof</span>(StorageItemThumbnail))</pre><pre class="alt">            {</pre><pre>                <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentException(<span class="str">"Expected a thumbnail"</span>);</pre><pre class="alt">            }</pre><pre>            <span class="kwrd">if</span> (targetType != <span class="kwrd">typeof</span>(ImageSource))</pre><pre class="alt">            {</pre><pre>                <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentException(<span class="str">"What are you trying to convert to here?"</span>);</pre><pre class="alt">            }</pre><pre>            StorageItemThumbnail thumbnail = (StorageItemThumbnail)<span class="kwrd">value</span>;</pre><pre class="alt">            image = <span class="kwrd">new</span> BitmapImage();</pre><pre>            image.SetSource(thumbnail);</pre><pre class="alt">        }</pre><pre>        <span class="kwrd">return</span> (image);</pre><pre class="alt">    }</pre><pre>    <span class="kwrd">public</span> <span class="kwrd">object</span> ConvertBack(<span class="kwrd">object</span> <span class="kwrd">value</span>, Type targetType, <span class="kwrd">object</span> parameter, <span class="kwrd">string</span> language)</pre><pre class="alt">    {</pre><pre>        <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();</pre><pre class="alt">    }</pre><pre>}  </pre></div>

</div>
<h5>&nbsp;</h5>
<h5>3. Bind the filelist (from step 1) to a ListView (or an Items Control of your choice), and use the converter</h5>
<p>XAML:</p>
<p>Declare the Converter as a resource</p>
<div class="csharpcode"><pre class="alt"><span class="kwrd">&lt;</span><span class="html">Page.Resources</span><span class="kwrd">&gt;</span></pre><pre>    <span class="kwrd">&lt;</span><span class="html">local:ThumbnailToImageConverter</span> <span class="attr">x:Key</span><span class="kwrd">="ThumbnailToImageConverter"</span> <span class="kwrd">/&gt;</span></pre><pre class="alt"><span class="kwrd">&lt;/</span><span class="html">Page.Resources</span><span class="kwrd">&gt;</span></pre></div>
<p>Use it in the ListView</p>
<div class="csharpcode"><pre class="alt"><span class="kwrd">&lt;</span><span class="html">ListView</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">x:Name</span><span class="kwrd">="FileListItemsControl"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Top"</span> <span class="attr">Height</span><span class="kwrd">="200"</span> <span class="attr">Margin</span><span class="kwrd">="20"</span> <span class="kwrd">&gt;</span></pre><pre>    <span class="kwrd">&lt;</span><span class="html">ListView.ItemsPanel</span><span class="kwrd">&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span></pre><pre>            <span class="kwrd">&lt;</span><span class="html">VirtualizingStackPanel</span> <span class="attr">Orientation</span><span class="kwrd">="Horizontal"</span> <span class="kwrd">/&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span></pre><pre>    <span class="kwrd">&lt;/</span><span class="html">ListView.ItemsPanel</span><span class="kwrd">&gt;</span></pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">ListView.ItemTemplate</span><span class="kwrd">&gt;</span></pre><pre>        <span class="kwrd">&lt;</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre><pre class="alt">          <span class="kwrd">&lt;</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre><pre>             <span class="kwrd">&lt;</span><span class="html">Image</span> <span class="attr">Source</span><span class="kwrd">="{Binding Thumbnail, Converter={StaticResource ThumbnailToImageConverter}}"</span> <span class="attr">Height</span><span class="kwrd">="150"</span> <span class="attr">Width</span><span class="kwrd">="300"</span> <span class="kwrd">/&gt;</span></pre><pre class="alt">             <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="{Binding FileName}"</span> <span class="attr">Style</span><span class="kwrd">="{StaticResource BodyTextBlockStyle}"</span> <span class="kwrd">/&gt;</span></pre><pre>          <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre><pre>    <span class="kwrd">&lt;/</span><span class="html">ListView.ItemTemplate</span><span class="kwrd">&gt;</span></pre><pre class="alt"><span class="kwrd">&lt;/</span><span class="html">ListView</span><span class="kwrd">&gt;</span></pre></div>



<p>C#:</p>
<p>Set the ItemsSource of the ListView to the fileList collection.</p>
<div class="csharpcode"><pre class="alt"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnNavigatedTo(NavigationEventArgs e)</pre><pre>{</pre><pre class="alt">    navigationHelper.OnNavigatedTo(e);</pre><pre>    <span class="kwrd">this</span>.FileListItemsControl.ItemsSource = fileList;</pre><pre class="alt">}</pre></div>



<p>That’s it – you should now be able to try it out!</p>
<h5>Show me the (full) codez! </h5>
<p>Full XAML and C# listing below:</p>
<p>XAML:</p>
<div class="csharpcode"><pre class="alt"><span class="kwrd">&lt;</span><span class="html">Page</span></pre><pre>    <span class="attr">x:Name</span><span class="kwrd">="pageRoot"</span></pre><pre class="alt">    <span class="attr">x:Class</span><span class="kwrd">="DevTest.BasicPage1"</span></pre><pre>    <span class="attr">DataContext</span><span class="kwrd">="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"</span></pre><pre class="alt">    <span class="attr">xmlns</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre><pre>    <span class="attr">xmlns:x</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre><pre class="alt">    <span class="attr">xmlns:local</span><span class="kwrd">="using:DevTest"</span></pre><pre>    <span class="attr">xmlns:common</span><span class="kwrd">="using:DevTest.Common"</span></pre><pre class="alt">    <span class="attr">xmlns:d</span><span class="kwrd">="http://schemas.microsoft.com/expression/blend/2008"</span></pre><pre>    <span class="attr">xmlns:mc</span><span class="kwrd">="http://schemas.openxmlformats.org/markup-compatibility/2006"</span></pre><pre class="alt">    <span class="attr">mc:Ignorable</span><span class="kwrd">="d"</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">&lt;</span><span class="html">Page.Resources</span><span class="kwrd">&gt;</span></pre><pre>        <span class="kwrd">&lt;</span><span class="html">local:ThumbnailToImageConverter</span> <span class="attr">x:Key</span><span class="kwrd">="ThumbnailToImageConverter"</span> <span class="kwrd">/&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;</span><span class="html">x:String</span> <span class="attr">x:Key</span><span class="kwrd">="AppName"</span><span class="kwrd">&gt;</span>File thumbnail sample<span class="kwrd">&lt;/</span><span class="html">x:String</span><span class="kwrd">&gt;</span></pre><pre>    <span class="kwrd">&lt;/</span><span class="html">Page.Resources</span><span class="kwrd">&gt;</span></pre><pre class="alt">  </pre><pre>    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Background</span><span class="kwrd">="{ThemeResource ApplicationPageBackgroundThemeBrush}"</span><span class="kwrd">&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;</span><span class="html">Grid.ChildrenTransitions</span><span class="kwrd">&gt;</span></pre><pre>            <span class="kwrd">&lt;</span><span class="html">TransitionCollection</span><span class="kwrd">&gt;</span></pre><pre class="alt">                <span class="kwrd">&lt;</span><span class="html">EntranceThemeTransition</span><span class="kwrd">/&gt;</span></pre><pre>            <span class="kwrd">&lt;/</span><span class="html">TransitionCollection</span><span class="kwrd">&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">Grid.ChildrenTransitions</span><span class="kwrd">&gt;</span></pre><pre>        <span class="kwrd">&lt;</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span></pre><pre class="alt">            <span class="kwrd">&lt;</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="140"</span><span class="kwrd">/&gt;</span></pre><pre>            <span class="kwrd">&lt;</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="*"</span><span class="kwrd">/&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span></pre><pre>&nbsp;</pre><pre class="alt">        <span class="rem">&lt;!-- Back button and page title --&gt;</span></pre><pre>        <span class="kwrd">&lt;</span><span class="html">Grid</span><span class="kwrd">&gt;</span></pre><pre class="alt">            <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span></pre><pre>                <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="120"</span><span class="kwrd">/&gt;</span></pre><pre class="alt">                <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="*"</span><span class="kwrd">/&gt;</span></pre><pre>            <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span></pre><pre class="alt">            <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">x:Name</span><span class="kwrd">="backButton"</span> <span class="attr">Margin</span><span class="kwrd">="39,59,39,0"</span> <span class="attr">Command</span><span class="kwrd">="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"</span></pre><pre>                        <span class="attr">Style</span><span class="kwrd">="{StaticResource NavigationBackButtonNormalStyle}"</span></pre><pre class="alt">                        <span class="attr">VerticalAlignment</span><span class="kwrd">="Top"</span></pre><pre>                        <span class="attr">AutomationProperties</span>.<span class="attr">Name</span><span class="kwrd">="Back"</span></pre><pre class="alt">                        <span class="attr">AutomationProperties</span>.<span class="attr">AutomationId</span><span class="kwrd">="BackButton"</span></pre><pre>                        <span class="attr">AutomationProperties</span>.<span class="attr">ItemType</span><span class="kwrd">="Navigation Button"</span><span class="kwrd">/&gt;</span></pre><pre class="alt">            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">x:Name</span><span class="kwrd">="pageTitle"</span> <span class="attr">Text</span><span class="kwrd">="{StaticResource AppName}"</span> <span class="attr">Style</span><span class="kwrd">="{StaticResource HeaderTextBlockStyle}"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span> </pre><pre>                        <span class="attr">IsHitTestVisible</span><span class="kwrd">="false"</span> <span class="attr">TextWrapping</span><span class="kwrd">="NoWrap"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Bottom"</span> <span class="attr">Margin</span><span class="kwrd">="0,0,30,40"</span><span class="kwrd">/&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span></pre><pre>        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">Content</span><span class="kwrd">="Pick files"</span> <span class="attr">Margin</span><span class="kwrd">="114,376,0,452"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">Click</span><span class="kwrd">="ButtonBase_OnClick"</span></pre><pre class="alt">                 <span class="attr">Width</span><span class="kwrd">="100"</span> <span class="attr">Height</span><span class="kwrd">="100"</span><span class="kwrd">/&gt;</span></pre><pre>        </pre><pre class="alt">        <span class="kwrd">&lt;</span><span class="html">ListView</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">x:Name</span><span class="kwrd">="FileListItemsControl"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Top"</span> <span class="attr">Height</span><span class="kwrd">="200"</span> <span class="attr">Margin</span><span class="kwrd">="20"</span> <span class="kwrd">&gt;</span></pre><pre>            <span class="kwrd">&lt;</span><span class="html">ListView.ItemsPanel</span><span class="kwrd">&gt;</span></pre><pre class="alt">                <span class="kwrd">&lt;</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span></pre><pre>                    <span class="kwrd">&lt;</span><span class="html">VirtualizingStackPanel</span> <span class="attr">Orientation</span><span class="kwrd">="Horizontal"</span> <span class="kwrd">/&gt;</span></pre><pre class="alt">                <span class="kwrd">&lt;/</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span></pre><pre>            <span class="kwrd">&lt;/</span><span class="html">ListView.ItemsPanel</span><span class="kwrd">&gt;</span></pre><pre class="alt">            <span class="kwrd">&lt;</span><span class="html">ListView.ItemTemplate</span><span class="kwrd">&gt;</span></pre><pre>                <span class="kwrd">&lt;</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre><pre class="alt">                    <span class="kwrd">&lt;</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre><pre>                        <span class="kwrd">&lt;</span><span class="html">Image</span> <span class="attr">Source</span><span class="kwrd">="{Binding Thumbnail, Converter={StaticResource ThumbnailToImageConverter}}"</span> <span class="attr">Height</span><span class="kwrd">="150"</span> <span class="attr">Width</span><span class="kwrd">="300"</span> <span class="kwrd">/&gt;</span></pre><pre class="alt">                        <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="{Binding FileName}"</span> <span class="attr">Style</span><span class="kwrd">="{StaticResource BodyTextBlockStyle}"</span> <span class="kwrd">/&gt;</span></pre><pre>                    <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre><pre class="alt">                <span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre><pre>            <span class="kwrd">&lt;/</span><span class="html">ListView.ItemTemplate</span><span class="kwrd">&gt;</span></pre><pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">ListView</span><span class="kwrd">&gt;</span></pre><pre>    <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span></pre><pre class="alt"><span class="kwrd">&lt;/</span><span class="html">Page</span><span class="kwrd">&gt;</span></pre></div>



<p>&nbsp;</p>
<p>C#:</p>
<div class="csharpcode"><pre class="alt"><span class="kwrd">using</span> DevTest.Common;</pre><pre><span class="kwrd">using</span> System;</pre><pre class="alt"><span class="kwrd">using</span> Windows.UI.Xaml;</pre><pre><span class="kwrd">using</span> Windows.UI.Xaml.Controls;</pre><pre class="alt"><span class="kwrd">using</span> Windows.UI.Xaml.Navigation;</pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">namespace</span> DevTest</pre><pre>{</pre><pre class="alt">    <span class="kwrd">using</span> System.Collections.ObjectModel;</pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">using</span> Windows.Storage.FileProperties;</pre><pre>    <span class="kwrd">using</span> Windows.Storage.Pickers;</pre><pre class="alt">&nbsp;</pre><pre>    <span class="rem">// Boilerplate stuff - deleting comments to reduce the code snippet size</span></pre><pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">sealed</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> BasicPage1 : Page</pre><pre>    {</pre><pre class="alt">&nbsp;</pre><pre>        <span class="kwrd">private</span> NavigationHelper navigationHelper;</pre><pre class="alt">        <span class="kwrd">private</span> ObservableDictionary defaultViewModel = <span class="kwrd">new</span> ObservableDictionary();</pre><pre>&nbsp;</pre><pre class="alt">        <span class="rem">// Boilerplate stuff - deleting comments to reduce the code snippet size</span></pre><pre>        <span class="kwrd">public</span> ObservableDictionary DefaultViewModel</pre><pre class="alt">        {</pre><pre>            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.defaultViewModel; }</pre><pre class="alt">        }</pre><pre>&nbsp;</pre><pre class="alt">        <span class="rem">// Boilerplate stuff - deleting comments to reduce the code snippet size</span></pre><pre>        <span class="kwrd">public</span> NavigationHelper NavigationHelper</pre><pre class="alt">        {</pre><pre>            get { <span class="kwrd">return</span> <span class="kwrd">this</span>.navigationHelper; }</pre><pre class="alt">        }</pre><pre>&nbsp;</pre><pre class="alt">        <span class="kwrd">private</span> ObservableCollection&lt;SimpleFileInfo&gt; fileList;</pre><pre>&nbsp;</pre><pre class="alt">        <span class="kwrd">public</span> BasicPage1()</pre><pre>        {</pre><pre class="alt">            <span class="kwrd">this</span>.InitializeComponent();</pre><pre>            <span class="kwrd">this</span>.navigationHelper = <span class="kwrd">new</span> NavigationHelper(<span class="kwrd">this</span>);</pre><pre class="alt">            <span class="kwrd">this</span>.navigationHelper.LoadState += navigationHelper_LoadState;</pre><pre>            <span class="kwrd">this</span>.navigationHelper.SaveState += navigationHelper_SaveState;</pre><pre class="alt">            fileList = <span class="kwrd">new</span> ObservableCollection&lt;SimpleFileInfo&gt;();</pre><pre>        }</pre><pre class="alt">&nbsp;</pre><pre>        <span class="rem">// Boilerplate stuff - deleting comments to reduce the code snippet size</span></pre><pre class="alt">        <span class="kwrd">private</span> <span class="kwrd">void</span> navigationHelper_LoadState(<span class="kwrd">object</span> sender, LoadStateEventArgs e)</pre><pre>        {</pre><pre class="alt">        }</pre><pre>&nbsp;</pre><pre class="alt">        <span class="rem">// Boilerplate stuff - deleting comments to reduce the code snippet size</span></pre><pre>        <span class="kwrd">private</span> <span class="kwrd">void</span> navigationHelper_SaveState(<span class="kwrd">object</span> sender, SaveStateEventArgs e)</pre><pre class="alt">        {</pre><pre>        }</pre><pre class="alt">&nbsp;</pre><pre>        <span class="rem">// Boilerplate stuff - deleting comments to reduce the code snippet size</span></pre><pre class="alt">        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnNavigatedTo(NavigationEventArgs e)</pre><pre>        {</pre><pre class="alt">            navigationHelper.OnNavigatedTo(e);</pre><pre>            <span class="kwrd">this</span>.FileListItemsControl.ItemsSource = fileList;</pre><pre class="alt">        }</pre><pre>&nbsp;</pre><pre class="alt">        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnNavigatedFrom(NavigationEventArgs e)</pre><pre>        {</pre><pre class="alt">            navigationHelper.OnNavigatedFrom(e);</pre><pre>        }</pre><pre class="alt">&nbsp;</pre><pre>        <span class="rem">// OUR CODE!!!</span></pre><pre class="alt">        <span class="kwrd">private</span> async <span class="kwrd">void</span> ButtonBase_OnClick(<span class="kwrd">object</span> sender, RoutedEventArgs e)</pre><pre>        {</pre><pre class="alt">            <span class="rem">// 1. Get FileOpenPicker ready</span></pre><pre>            var picker = <span class="kwrd">new</span> FileOpenPicker();</pre><pre class="alt">            picker.ViewMode = PickerViewMode.Thumbnail;</pre><pre>            picker.SuggestedStartLocation = PickerLocationId.ComputerFolder;</pre><pre class="alt">            </pre><pre>            <span class="rem">// 2. Add filters - it's required to have at least one filter</span></pre><pre class="alt">            <span class="rem">//    it CANNOT be a wildcard (i.e., no .*)</span></pre><pre>            picker.FileTypeFilter.Add(<span class="str">".docx"</span>);</pre><pre class="alt">            picker.FileTypeFilter.Add(<span class="str">".pptx"</span>);</pre><pre>            picker.FileTypeFilter.Add(<span class="str">".xlsx"</span>);</pre><pre class="alt">            picker.FileTypeFilter.Add(<span class="str">".xls"</span>);</pre><pre>            picker.FileTypeFilter.Add(<span class="str">".jpg"</span>);</pre><pre class="alt">            picker.FileTypeFilter.Add(<span class="str">".png"</span>);</pre><pre>            picker.FileTypeFilter.Add(<span class="str">".pdf"</span>);</pre><pre class="alt">&nbsp;</pre><pre>            <span class="rem">// 3. Call the file picker</span></pre><pre class="alt">            var file = await picker.PickMultipleFilesAsync();</pre><pre>&nbsp;</pre><pre class="alt">            <span class="kwrd">if</span> (file != <span class="kwrd">null</span>)</pre><pre>            {</pre><pre class="alt">                <span class="kwrd">foreach</span> (var storageFile <span class="kwrd">in</span> file)</pre><pre>                {</pre><pre class="alt">                    <span class="rem">// fileList = new ObservableCollection&lt;SimpleFileInfo&gt;(); in the constructor</span></pre><pre>                    <span class="rem">// SimpleFileInfo is a class with a string FileName and a StorageItemThumbnail Thumbnail field.</span></pre><pre class="alt">                    fileList.Add(<span class="kwrd">new</span> SimpleFileInfo</pre><pre>                    {</pre><pre class="alt">                        FileName = storageFile.Name,</pre><pre>                        <span class="rem">// 4. Get image thumbnails!!</span></pre><pre class="alt">                        Thumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem)</pre><pre>                    });</pre><pre class="alt">                }</pre><pre>&nbsp;</pre><pre class="alt">            }</pre><pre>        }</pre><pre class="alt">    }</pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> SimpleFileInfo</pre><pre>    {</pre><pre class="alt">        <span class="kwrd">public</span> <span class="kwrd">string</span> FileName { get; set; }</pre><pre>&nbsp;</pre><pre class="alt">        <span class="kwrd">public</span> StorageItemThumbnail Thumbnail { get; set; }</pre><pre>    }</pre><pre class="alt">}</pre></div>



<p>&nbsp;</p>
<p>Thanks for reading!
<p>Amar
<p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>Slide to shutdown in Windows 8.1 – great for touch devices</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/slide-to-shutdown-in-windows-8-1-great-for-touch-devices</link>
      <pubDate>Mon, 19 May 2014 21:24:47 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2014/05/19/slide-to-shutdown-in-windows-8-1-great-for-touch-devices/</guid>
      <description><![CDATA[&#160;  This is going to be a small post!   I found a small gem in Windows\System32 folder called...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>This is going to be a small post! </p>  <p>I found a small gem in Windows\System32 folder called SlideToShutDown.exe</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3323.image_645DA0D5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3323.image_5F00_645DA0D5.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3515.image_thumb_71C6448C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3515.image_5F00_thumb_5F00_71C6448C.png" width="644" height="169" /></a> </p>  <p>When I ran it, I saw this:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7215.image_7566F01A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7215.image_5F00_7566F01A.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4338.image_thumb_76CDA39D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4338.image_5F00_thumb_5F00_76CDA39D.png" width="644" height="364" /></a> </p>  <p>Thought it was really cool to have a shortcut to this on the desktop, so that I can shut down my machine with a tap and a slide!</p>  <p>Here’s how I did it:</p>  <p>Right click on the exe in the System32 folder, and click on “Send to desktop”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5861.image_7521F92B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5861.image_5F00_7521F92B.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0042.image_thumb_7BD7935F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0042.image_5F00_thumb_5F00_7BD7935F.png" width="644" height="426" /></a> </p>  <p>You should see the shortcut on your desktop now. Right click on the shortcut and “Pin to Start”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1805.image_41EAE124.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1805.image_5F00_41EAE124.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6153.image_thumb_3E6C503A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6153.image_5F00_thumb_5F00_3E6C503A.png" width="422" height="484" /></a> </p>  <p>And that’s it:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5074.image_398C2D2F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5074.image_5F00_398C2D2F.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6355.image_thumb_739D8ABF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6355.image_5F00_thumb_5F00_739D8ABF.png" width="644" height="441" /></a> </p>  <p>Thanks for reading!</p>  <p>Amar</p>  <p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>Status Bar (SystemTray) for Silverlight Apps for Windows Phone 8.1?</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/status-bar-systemtray-for-silverlight-apps-for-windows-phone-8-1</link>
      <pubDate>Mon, 12 May 2014 04:15:15 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2014/05/12/status-bar-systemtray-for-silverlight-apps-for-windows-phone-8-1/</guid>
      <description><![CDATA[In my last post, I talked about using the “Status Bar” in Windows Phone 8.1 to make optimal use of...]]></description>
      <content:encoded><![CDATA[<p>In my <a href="http://blogs.msdn.com/b/amar/archive/2014/05/12/status-bar-in-windows-phone-8-1.aspx">last post</a>, I talked about using the “Status Bar” in Windows Phone 8.1 to make optimal use of our screen space, like the Bing apps do. What I forgot to mention, was the code mentioned in that post applies only to the new Windows Phone 8.1 Universal Apps (i.e., targeting Windows RT).</p>  <p>If you are using <strong>Silverlight for Windows Phone 8.1,</strong> we will have to use the <strong>Microsoft.Phone.Shell.SystemTray </strong>class instead.</p>  <p>You could easily set the SystemTray properties in your XAML page like this:</p>  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">   <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">     <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">phone:PhoneApplicationPage</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #ff0000">x:Class</span><span style="color: #0000ff">=&quot;SLApp.MainPage&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #ff0000">xmlns:x</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #ff0000">xmlns:phone</span><span style="color: #0000ff">=&quot;clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #ff0000">xmlns:shell</span><span style="color: #0000ff">=&quot;clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #ff0000">xmlns:d</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>     <span style="color: #ff0000">xmlns:mc</span><span style="color: #0000ff">=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>     <span style="color: #ff0000">mc:Ignorable</span><span style="color: #0000ff">=&quot;d&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>     <span style="color: #ff0000">FontFamily</span><span style="color: #0000ff">=&quot;{StaticResource PhoneFontFamilyNormal}&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>     <span style="color: #ff0000">FontSize</span><span style="color: #0000ff">=&quot;{StaticResource PhoneFontSizeNormal}&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>     <span style="color: #ff0000">Foreground</span><span style="color: #0000ff">=&quot;{StaticResource PhoneForegroundBrush}&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>     <span style="color: #ff0000">SupportedOrientations</span><span style="color: #0000ff">=&quot;Portrait&quot;</span> <span style="color: #ff0000">Orientation</span><span style="color: #0000ff">=&quot;Portrait&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>     <span style="color: #ff0000">shell:SystemTray</span>.<span style="color: #ff0000">IsVisible</span><span style="color: #0000ff">=&quot;True&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>     <span style="color: #ff0000">shell:SystemTray</span>.<span style="color: #ff0000">BackgroundColor</span><span style="color: #0000ff">=&quot;Blue&quot;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>     <span style="color: #ff0000">shell:SystemTray</span>.<span style="color: #ff0000">ForegroundColor</span><span style="color: #0000ff">=&quot;White&quot;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span>     <span style="color: #ff0000">shell:SystemTray</span>.<span style="color: #ff0000">Opacity</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #0000ff">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p>And then, in the xaml.cs, you can set the ProgressIndicator like this:</p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> MainPage()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     InitializeComponent();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     var prog = <span style="color: #0000ff">new</span> ProgressIndicator { Text = <span style="color: #006080">&quot;My app&quot;</span>, IsVisible=<span style="color: #0000ff">true</span>, IsIndeterminate=<span style="color: #0000ff">false</span>,Value=0 };</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     SystemTray.SetProgressIndicator(<span style="color: #0000ff">this</span>, prog);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>And we’re done!</p>

<h5>To summarize:</h5>

<p>Windows Phone 8.1 (RT/Universal App) --&gt; use Windows.UI.ViewManagement.StatusBar</p>

<p>Silverlight app for Windows Phone 8.1 --&gt; use Microsoft.Phone.Shell.SystemTray</p>

<p>&#160;</p>

<p>Thank you, @xuggs for bringing this up! Hope this helps :)</p>

<p>&#160;</p>

<p>Thanks for reading!</p>

<p>Amar</p>

<p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>Status Bar in Windows Phone 8.1</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/status-bar-in-windows-phone-8-1</link>
      <pubDate>Sun, 11 May 2014 12:02:02 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2014/05/11/status-bar-in-windows-phone-8-1/</guid>
      <description><![CDATA[Have you used the Bing apps for Windows Phone? You know, Bing News, Weather, Travel etc.? How...]]></description>
      <content:encoded><![CDATA[<div class="csharpcode"></div>  <p>Have you used the Bing apps for Windows Phone? You know, <a href="http://www.windowsphone.com/en-us/store/app/news/9c3e8cad-6702-4842-8f61-b8b33cc9caf1">Bing News</a>, <a href="http://www.windowsphone.com/en-us/store/app/weather/63c2a117-8604-44e7-8cef-df10be3a57c8">Weather</a>, <a href="http://www.windowsphone.com/en-us/store/app/travel/19cd0687-980b-4838-8880-5f68aba1671e">Travel</a> etc.? How about the email client?</p>  <p>Noticed how these apps use the Status Bar on the top?</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0334.wp_ss_20140511_0002_59FC089F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0334.wp_5F00_ss_5F00_20140511_5F00_0002_5F00_59FC089F.png"><img title="wp_ss_20140511_0002" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="wp_ss_20140511_0002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3581.wp_ss_20140511_0002_thumb_551BE594.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3581.wp_5F00_ss_5F00_20140511_5F00_0002_5F00_thumb_5F00_551BE594.png" width="274" height="484" /></a>&#160;&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3817.wp_ss_20140511_0003_5FDBCD9A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3817.wp_5F00_ss_5F00_20140511_5F00_0003_5F00_5FDBCD9A.png"><img title="wp_ss_20140511_0003" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="wp_ss_20140511_0003" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7870.wp_ss_20140511_0003_thumb_2E727AA9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7870.wp_5F00_ss_5F00_20140511_5F00_0003_5F00_thumb_5F00_2E727AA9.png" width="274" height="484" /></a>&#160;&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1072.wp_ss_20140511_0005_594D6F6C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1072.wp_5F00_ss_5F00_20140511_5F00_0005_5F00_594D6F6C.png"><img title="wp_ss_20140511_0005" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="wp_ss_20140511_0005" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4274.wp_ss_20140511_0005_thumb_089EE4F7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4274.wp_5F00_ss_5F00_20140511_5F00_0005_5F00_thumb_5F00_089EE4F7.png" width="274" height="484" /></a> </p>  <p></p>  <p></p>  <p>I think that is very efficient use of the screen space, while not really hiding the status bar. But until I saw how the mail client app does that, I didn’t really figure out how I could do that in my apps. The solution turns out to be extremely simple!</p>  <h3>Using the status bar for the title of your app. (AKA., more screen space for the content)</h3>  <p><strong>Summary:</strong> Set the text property of the progress bar, which is a part of the status bar.</p>  <p><strong>Details:</strong></p>  <p>If you look at the <a href="http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.ui.viewmanagement.statusbar%28v=win.10%29.aspx">MSDN documentation for the StatusBar</a> class, you’ll see just a handful of properties and methods that you can work with. When I saw how the email client on WP makes use of the status bar, it was obvious how the Bing apps use it!</p>  <p>You can try this piece of code in the OnLaunched event handler in your App.xaml.cs:</p>  <div class="csharpcode">   <pre class="alt"><span class="rem">// Set the background color of the status bar, and DON'T FORGET to set the opacity!</span></pre>

  <pre>var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();</pre>

  <pre class="alt">statusBar.BackgroundColor = (App.Current.Resources[<span class="str">&quot;PhoneAccentBrush&quot;</span>] <span class="kwrd">as</span> SolidColorBrush).Color;</pre>

  <pre>statusBar.BackgroundOpacity = 1;</pre>

  <pre class="alt">&#160;</pre>

  <pre><span class="rem">// Set the text on the ProgressIndicator, and show it.</span></pre>

  <pre class="alt">statusBar.ProgressIndicator.Text = <span class="str">&quot;My cool app&quot;</span>;</pre>

  <pre>statusBar.ProgressIndicator.ShowAsync();</pre>

  <pre class="alt">&#160;</pre>

  <pre><span class="rem">// If the progress value is null (which is the default value), the progress indicator is in an </span></pre>

  <pre><span class="rem">indeterminate state (dots moving from left to right).</span></pre>

  <pre class="alt"><span class="rem">// Set it to 0 if you don't wish to show the progress bar.</span></pre>

  <pre>statusBar.ProgressIndicator.ProgressValue = 0;</pre>
</div>


<p>So, the key thing is to set the Text property of the ProgressIndicator on the StatusBar, and call the ShowAsync method. Setting the background color and opacity of the status bar is stuff that you could choose to do if you have a particular theme for the app (or choose the phone accent brush).</p>

<p>And that’s it, really! Here are the screenshots of what it looks like with different themes on the phone.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3652.myCoolAppBlue_5CF0ABAB.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3652.myCoolAppBlue_5F00_5CF0ABAB.png"><img title="myCoolAppBlue" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="myCoolAppBlue" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4064.myCoolAppBlue_thumb_5E54CE7D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4064.myCoolAppBlue_5F00_thumb_5F00_5E54CE7D.png" width="292" height="484" /></a>&#160;&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1781.myCoolApp_027CB9BE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1781.myCoolApp_5F00_027CB9BE.png"><img title="myCoolApp" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="myCoolApp" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1727.myCoolApp_thumb_74AD0473.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1727.myCoolApp_5F00_thumb_5F00_74AD0473.png" width="292" height="484" /></a> </p>

<p></p>

<h3>Making use of the screen space of a transparent status bar</h3>

<p>Say you have an app which has a photo viewer section. You would obviously want to use up as much screen space as possible, but may be also have some branding – at least the name of the app. Even if you followed all the steps above, and set the opacity of the status bar to 0, you would see something like this:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8510.photoStatusBar_76112745.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8510.photoStatusBar_5F00_76112745.png"><img title="photoStatusBar" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="photoStatusBar" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3073.photoStatusBar_thumb_02A3F5C4.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3073.photoStatusBar_5F00_thumb_5F00_02A3F5C4.png" width="292" height="484" /></a> </p>

<p>See how the Status Bar stays on top, even if you set the opacity to 0? That doesn’t look too good. What would be great is if we could have something like this:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0753.photoStatusBarFull_13411214.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0753.photoStatusBarFull_5F00_13411214.png"><img title="photoStatusBarFull" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="photoStatusBarFull" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5126.photoStatusBarFull_thumb_7905CA51.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5126.photoStatusBarFull_5F00_thumb_5F00_7905CA51.png" width="292" height="484" /></a>&#160; </p>

<p>To do this, we need to use the entire Window space available, including what is usually allocated for the status bar and the app bar.</p>

<p>So, use this piece code in the OnLaunched event handler in your App.xaml.cs:</p>

<p></p>

<div class="csharpcode">
  <pre class="alt"><p><span class="rem">// Set the desired bounds on the application view to use the core window, i.e., the entire screen </span><span class="rem">(including app bar and status bar</span></p></pre>

  <pre>var applicationView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();</pre>

  <pre class="alt">applicationView.SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);</pre>
</div>


<p>That’s it for today! Hope this helped.</p>

<p>&#160;</p>

<p>Thanks for reading!</p>

<p>Amar</p>

<p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>Creating a simple “Tile” button in HTML/CSS and as an ASP.NET MVC HtmlHelper</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/creating-a-simple-tile-button-in-htmlcss-and-as-an-asp-net-mvc-htmlhelper</link>
      <pubDate>Fri, 15 Nov 2013 08:39:05 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2013/11/15/creating-a-simple-tile-button-in-htmlcss-and-as-an-asp-net-mvc-htmlhelper/</guid>
      <description><![CDATA[If you have worked with SharePoint 2013, you may have noticed a “tile” button. Something that looks...]]></description>
      <content:encoded><![CDATA[<p>If you have worked with SharePoint 2013, you may have noticed a “tile” button. Something that looks like this:</p>  <table cellspacing="0" cellpadding="2" width="400" border="0"><tbody>     <tr>       <td valign="top" width="200"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8182.image_374C8FED.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8182.image_5F00_374C8FED.png"><img title="image" style="margin: 0px; display: inline; background-image: none;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1157.image_thumb_593A8322.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1157.image_5F00_thumb_5F00_593A8322.png" width="202" height="205" /></a></td>        <td valign="top" width="200"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8372.image_1F4DD0E7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8372.image_5F00_1F4DD0E7.png"><img title="image" style="margin: 0px; display: inline; background-image: none;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3652.image_thumb_429D563D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3652.image_5F00_thumb_5F00_429D563D.png" width="204" height="203" /></a></td>     </tr>      <tr>       <td valign="top" width="200">         <p align="center">Normal State</p>       </td>        <td valign="top" width="200">         <p align="center">On mouse over (hover)</p>       </td>     </tr>   </tbody></table>&#160;&#160;&#160;&#160; <p>This looks good (at least to me) and I wanted to find a simple way to create such a button. I’m mainly a XAML guy, and can create something like this VERY easily in XAML; and I can reuse this as a single unit, like a button. But with HTML, it’s a little different. To make this a reusable component, I’ll use ASP.NET MVC and make this a HtmlHelper. For this reason, I wanted to build this without JavaScript – it’s easier to create a HtmlHelper with just HTML and CSS.</p>  <p>To start things off, I created a plain HTML/CSS version of the Tile button:</p>  <div class="csharpcode">   <pre class="alt"><span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;tile&quot;</span> <span class="attr">style</span><span class="kwrd">=&quot;background:url(‘Pic.jpg'); background-size:200px 200px&quot;</span> <span class="kwrd">&gt;</span></pre>

  <pre>      <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;caption&quot;</span> <span class="attr">onclick</span><span class="kwrd">=&quot;alert('Hi!');&quot;</span> <span class="kwrd">&gt;</span></pre>

  <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;</span>Some caption<span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span></pre>

  <pre>            <span class="kwrd">&lt;</span><span class="html">p</span> <span class="attr">id</span><span class="kwrd">=&quot;description&quot;</span><span class="kwrd">&gt;</span>Some lengthy description that may potentially overflow into two lines<span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span></pre>

  <pre class="alt">       <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>

  <pre><span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
</div>


<p>And the CSS:</p>

<div class="csharpcode">
  <pre class="alt">.tile{</pre>

  <pre>    height: 200px;</pre>

  <pre class="alt">    width: 200px;</pre>

  <pre>    overflow: hidden;</pre>

  <pre class="alt">    background-repeat: no-repeat;</pre>

  <pre>    max-width: 100%;</pre>

  <pre class="alt">    text-align: center;</pre>

  <pre>    vertical-align: middle;</pre>

  <pre class="alt">    background-size:200px 200px;</pre>

  <pre>}</pre>

  <pre class="alt">&#160;</pre>

  <pre>.caption{</pre>

  <pre class="alt">    background-color: rgba(50,50,50,0.4);</pre>

  <pre>    overflow: hidden;</pre>

  <pre class="alt">    color: #fff;</pre>

  <pre>    font-weight: bold;</pre>

  <pre class="alt">    margin: 150px 0px 0px 0px;</pre>

  <pre>    height: 200px;</pre>

  <pre class="alt">    width: 200px;</pre>

  <pre>}</pre>

  <pre class="alt">&#160;</pre>

  <pre>.caption:hover {</pre>

  <pre class="alt">    transition: margin .5s;</pre>

  <pre>    margin: 0px 0px 20px 0px;</pre>

  <pre class="alt">    background-color: rgba(50,50,50,0.4);</pre>

  <pre>    cursor: pointer;</pre>

  <pre class="alt">}</pre>

  <pre>&#160;</pre>

  <pre class="alt">#description{</pre>

  <pre>    overflow: hidden;</pre>

  <pre class="alt">    margin: 25px 0px 0px 0px;</pre>

  <pre>}</pre>
</div>


<p>I’ve used CSS3 transitions for the smooth animation, and it works beautifully on most modern browsers.</p>

<p>Next, I wanted to make this a reusable control and not leave it as just a bunch of HTML tags that has to be repeated all over.</p>

<h3>Creating an ASP.NET MVC HtmlHelper</h3>

<p>Less talk, more code :D</p>

<div class="csharpcode">
  <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> MyHelpers</pre>

  <pre>    {</pre>

  <pre class="alt">        <span class="kwrd">public</span> <span class="kwrd">static</span> MvcHtmlString TileButton(<span class="kwrd">string</span> backgroundUrl, <span class="kwrd">string</span> jsAction, </pre>

  <pre>            <span class="kwrd">string</span> caption, <span class="kwrd">string</span> description = <span class="str">&quot;&quot;</span>)</pre>

  <pre class="alt">        {</pre>

  <pre>            var outerDiv = <span class="kwrd">new</span> TagBuilder(<span class="str">&quot;div&quot;</span>);</pre>

  <pre class="alt">            var captionDiv = <span class="kwrd">new</span> TagBuilder(<span class="str">&quot;div&quot;</span>);</pre>

  <pre>            var captionP = <span class="kwrd">new</span> TagBuilder(<span class="str">&quot;p&quot;</span>);</pre>

  <pre class="alt">            var descP = <span class="kwrd">new</span> TagBuilder(<span class="str">&quot;p&quot;</span>);</pre>

  <pre>&#160;</pre>

  <pre class="alt">            outerDiv.AddCssClass(<span class="str">&quot;tile&quot;</span>);</pre>

  <pre>            <span class="rem">//style=&quot;background:url('AmarProfilePicSmall.jpg'); </span></pre>

  <pre class="alt">            <span class="rem">//       background-size:200px 200px&quot;</span></pre>

  <pre>            outerDiv.MergeAttribute(<span class="str">&quot;style&quot;</span>, </pre>

  <pre class="alt">                <span class="str">&quot;background:url(&quot;</span> + backgroundUrl + <span class="str">&quot;); background-size:200px 200px&quot;</span>);</pre>

  <pre>            </pre>

  <pre class="alt">            captionDiv.AddCssClass(<span class="str">&quot;caption&quot;</span>);</pre>

  <pre>            descP.AddCssClass(<span class="str">&quot;description&quot;</span>);</pre>

  <pre class="alt">            captionDiv.MergeAttribute(<span class="str">&quot;onclick&quot;</span>, jsAction);</pre>

  <pre>&#160;</pre>

  <pre class="alt">            captionP.SetInnerText(caption);</pre>

  <pre>            descP.SetInnerText(description);</pre>

  <pre class="alt">&#160;</pre>

  <pre>            captionDiv.InnerHtml = captionP.ToString() + descP.ToString();</pre>

  <pre class="alt">            outerDiv.InnerHtml = captionDiv.ToString();</pre>

  <pre>&#160;</pre>

  <pre class="alt">            <span class="kwrd">return</span> <span class="kwrd">new</span> MvcHtmlString(outerDiv.ToString());</pre>

  <pre>        }</pre>

  <pre class="alt">    }</pre>
</div>


<p>The code is pretty simple, so at an overview level, ’m using TagBuilder to create the components that I used in HTML for the tile. I’m going to reuse the same CSS I used earlier, and have copied it to the site.css file in the Content folder in a new ASP.NET MVC project.</p>

<p>And although I could’ve created this as an extension method to the HtmlHelper class, I created this as a static method to start with, so I can use it like this in my views:</p>

<p>@TileButtonSample.Helpers.MyHelpers.TileButton(&quot;../Images/AmarProfilePicSmall.jpg&quot;,</p>

<p>&quot;alert('Hi');&quot;, &quot;Caption&quot;, &quot;Some lengthy description&quot;)</p>

<p></p>

<p>And, that’s about it! A short post this time – and hopefully simple enough.</p>

<p>If you think this can be improved, please mention what approach you would take to implement this.</p>



<p>Thanks for reading!</p>

<p>Amar</p>



<p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>How are shortcuts created and managed on the Windows 8 Start screen?</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/how-are-shortcuts-created-and-managed-on-the-windows-8-start-screen</link>
      <pubDate>Wed, 06 Mar 2013 14:00:17 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2013/03/06/how-are-shortcuts-created-and-managed-on-the-windows-8-start-screen/</guid>
      <description><![CDATA[To summarize:     Shortcuts can be created on the Windows 8 Start screen by creating a folder in...]]></description>
      <content:encoded><![CDATA[<p>To summarize:</p>  <ul>   <li>Shortcuts can be created on the Windows 8 Start screen by creating a folder in “C:\ProgramData\Microsoft\Windows\Start Menu\Programs”</li>    <li>Multiple shortcuts to the same exe or app with the same AppId results in only one shortcut on the Start screen, based on its name in alphanumeric ascending order.</li>    <li>Windows remembers the pinned/unpinned status (including the tile group it was pinned in) of the shortcut on the Start screen based on the exe/app it points to.</li>    <li>When we uninstall and reinstall the app, if there is a shortcut created to an app in the same location as the earlier install, the pinned/unpinned status is maintained too.</li> </ul>  <h5>Here is a more detailed version:</h5>  <p>Shortcuts can be created on the Windows 8 Start Screen by creating a folder in “C:\ProgramData\Microsoft\Windows\Start Menu\Programs”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1663.clip_image0025_5DDA80BC.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1663.clip_5F00_image0025_5F00_5DDA80BC.jpg"><img style="display: inline; background-image: none;" title="clip_image002[5]" border="0" alt="clip_image002[5]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2630.clip_image0025_thumb_5BBD81F3.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2630.clip_5F00_image0025_5F00_thumb_5F00_5BBD81F3.jpg" width="608" height="347" /></a></p>  <p>To understand how Windows keeps track of the shortcuts, I copied an exe to two folders, created shortcuts for each of them and copied them to the folder in Start Menu\Programs.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0167.clip_image001_40A4B2E5.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0167.clip_5F00_image001_5F00_40A4B2E5.jpg"><img style="display: inline; background-image: none;" title="clip_image001" border="0" alt="clip_image001" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0576.clip_image001_thumb_3E87B41C.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0576.clip_5F00_image001_5F00_thumb_5F00_3E87B41C.jpg" width="628" height="520" /></a></p>  <p>As expected, both the shortcuts show up in the start screen. I also went ahead and pinned them in a tile group.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7827.clip_image005_4DDB162B.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7827.clip_5F00_image005_5F00_4DDB162B.jpg"><img style="display: inline; background-image: none;" title="clip_image005" border="0" alt="clip_image005" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0068.clip_image005_thumb_7A179D0F.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0068.clip_5F00_image005_5F00_thumb_5F00_7A179D0F.jpg" width="622" height="439" /></a></p>  <p>Then I unpinned a shortcut from the Start screen. Since this was only unpinned, and not deleted/uninstalled, it continues to show up in “Apps”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7485.clip_image006_466F30B1.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7485.clip_5F00_image006_5F00_466F30B1.jpg"><img style="display: inline; background-image: none;" title="clip_image006" border="0" alt="clip_image006" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2210.clip_image006_thumb_64D9719A.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2210.clip_5F00_image006_5F00_thumb_5F00_64D9719A.jpg" width="244" height="170" /></a>&#160;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2210.clip_image008_158C7946.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2210.clip_5F00_image008_5F00_158C7946.jpg"><img style="margin: 0px; display: inline; background-image: none;" title="clip_image008" border="0" alt="clip_image008" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6406.clip_image008_thumb_742CD3A9.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6406.clip_5F00_image008_5F00_thumb_5F00_742CD3A9.jpg" width="244" height="134" /></a></p>  <p>Then I went ahead and deleted the shortcut from the folder in Start Menu\Programs.</p>  <p>As expected the shortcut doesn’t appear in the “App” anymore</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6406.clip_image010_6515F4CF.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6406.clip_5F00_image010_5F00_6515F4CF.jpg"><img style="margin: 0px; display: inline; background-image: none;" title="clip_image010" border="0" alt="clip_image010" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0537.clip_image010_thumb_43B64F33.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0537.clip_5F00_image010_5F00_thumb_5F00_43B64F33.jpg" width="244" height="98" /></a></p>  <p>Next I created a shortcut to the app (which I had copied to a folder my Program Files), named it “ThemesDemo - Shortcut1” this time.</p>  <p>It didn’t show up on the Start screen, but was available under “Apps”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7870.clip_image012_777E4584.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7870.clip_5F00_image012_5F00_777E4584.jpg"><img style="display: inline; background-image: none;" title="clip_image012" border="0" alt="clip_image012" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7571.clip_image012_thumb_561E9FE8.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7571.clip_5F00_image012_5F00_thumb_5F00_561E9FE8.jpg" width="244" height="123" /></a></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2604.image_4707C10E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2604.image_5F00_4707C10E.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2262.image_thumb_657201F7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2262.image_5F00_thumb_5F00_657201F7.png" width="347" height="484" /></a></p>  <p>Next, I created a copy of the shortcut and named it “ThemesDemo – Shortcut2” to see if it shows up pinned in the Start but it didn’t.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4403.clip_image0029_5CA1F9AB.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4403.clip_5F00_image0029_5F00_5CA1F9AB.jpg"><img style="display: inline; background-image: none;" title="clip_image002[9]" border="0" alt="clip_image002[9]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1373.clip_image0029_thumb_28F98D4D.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1373.clip_5F00_image0029_5F00_thumb_5F00_28F98D4D.jpg" width="588" height="221" /></a></p>  <p>Furthermore, “ThemesDemo – Shortcut2” didn’t show up under “Apps” either. As it turns out, if you have two shortcuts pointing to an app with the same AppId or the same exe, only one shortcut will show up in the Start screen, and this is chosen based on the alphanumeric ascending order of the name of the shortcuts. To check this, I renamed “ThemesDemo – Shortcut2” to “AAA”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5700.clip_image00211_605F9E7B.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5700.clip_5F00_image00211_5F00_605F9E7B.jpg"><img style="display: inline; background-image: none;" title="clip_image002[11]" border="0" alt="clip_image002[11]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1665.clip_image00211_thumb_45B30262.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1665.clip_5F00_image00211_5F00_thumb_5F00_45B30262.jpg" width="465" height="237" /></a></p>  <p>And this shows up in “Apps”.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7534.image_7D191390.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7534.image_5F00_7D191390.png"><img style="margin: 0px; display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4382.image_thumb_1059CA30.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4382.image_5F00_thumb_5F00_1059CA30.png" width="356" height="484" /></a></p>  <p>Then I went ahead and deleted the exe in the Program Files and the shortcut in the “Start Menu\Programs” folder too, and copied the exe and created a shortcut again (to simulate reinstalling an app).</p>  <p>Again, the shortcut didn’t show up on the start screen, but shows up in “Apps”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8015.clip_image00215_604F78AE.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8015.clip_5F00_image00215_5F00_604F78AE.jpg"><img style="display: inline; background-image: none;" title="clip_image002[15]" border="0" alt="clip_image002[15]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7607.clip_image00215_thumb_3EEFD312.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7607.clip_5F00_image00215_5F00_thumb_5F00_3EEFD312.jpg" width="244" height="126" /></a></p>  <p>I went ahead and pinned this to the Start screen again.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8168.clip_image00217_5DC646F0.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8168.clip_5F00_image00217_5F00_5DC646F0.jpg"><img style="display: inline; background-image: none;" title="clip_image002[17]" border="0" alt="clip_image002[17]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8168.clip_image00217_thumb_2A1DDA92.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8168.clip_5F00_image00217_5F00_thumb_5F00_2A1DDA92.jpg" width="244" height="229" /></a></p>  <p>And I tried uninstalling (deleting shortcut and exe)</p>  <p>As expected it doesn’t show up pinned in the Start screen or in “Apps”</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0652.clip_image00219_5AD0E23D.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0652.clip_5F00_image00219_5F00_5AD0E23D.jpg"><img style="display: inline; background-image: none;" title="clip_image002[19]" border="0" alt="clip_image002[19]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6180.clip_image00219_thumb_6E1198DC.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6180.clip_5F00_image00219_5F00_thumb_5F00_6E1198DC.jpg" width="244" height="191" /></a>&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8156.clip_image00221_1EC4A088.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8156.clip_5F00_image00221_5F00_1EC4A088.jpg"><img style="display: inline; background-image: none;" title="clip_image002[21]" border="0" alt="clip_image002[21]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2376.clip_image00221_thumb_7D64FAEB.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2376.clip_5F00_image00221_5F00_thumb_5F00_7D64FAEB.jpg" width="244" height="96" /></a></p>  <p>Then I copied the exe and shortcut back (reinstall) and it shows up in the <strong>same tile group</strong> I had pinned it in before uninstalling the app.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8625.clip_image00223_033F9E85.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8625.clip_5F00_image00223_5F00_033F9E85.jpg"><img style="display: inline; background-image: none;" title="clip_image002[23]" border="0" alt="clip_image002[23]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1781.clip_image00223_thumb_4CEE7675.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1781.clip_5F00_image00223_5F00_thumb_5F00_4CEE7675.jpg" width="217" height="244" /></a></p>  <p>Hope this gives a better understanding of how shortcuts are created and tracked in the Windows 8 Start screen.</p>  <p>&#160;</p>  <p><em><strong>Note</strong>: I learned these by hit and miss, and so may not be an accurate description of how things work internally.</em></p>  <p>&#160;</p>  <p>Thanks for reading!</p>  <p>Amar</p>  <p>&#160;</p>  <p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>Better control(s) with Visual State Manager</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/better-controls-with-visual-state-manager</link>
      <pubDate>Tue, 26 Feb 2013 13:23:46 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2013/02/26/better-controls-with-visual-state-manager/</guid>
      <description><![CDATA[We had talked about Visual States very briefly when we were discussing how we handle different views...]]></description>
      <content:encoded><![CDATA[<p>We had talked about Visual States very briefly when we were discussing <a href="http://blogs.msdn.com/b/amar/archive/2012/10/08/handling-different-orientations-and-views-with-windows-store-apps.aspx" target="_blank">how we handle different views and orientation</a> in a Windows Store App. Let’s go a step further and understand the concept of Visual States and how we can leverage this to create better styles for the existing controls.</p><p>To understand why this is important, let me ask you – have you ever faced this scenario?</p><p>You want to create an app with a custom theme – have a nice light gray background (inspired by VS2012, perhaps?) and green buttons (assume, for some reason, your users like this!), and so you set the background of the button to green and you get something like this:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4544.image_31D48225.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4544.image_5F00_31D48225.png"><img width="244" height="199" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1300.image_thumb_5BD4804D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1300.image_5F00_thumb_5F00_5BD4804D.png" border="0"></a>
</p><p>So far, so good. This is what your users asked for.</p><p>But…</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1586.image_61AF23E6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1586.image_5F00_61AF23E6.png"><img width="229" height="244" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4617.image_thumb_6789C77F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4617.image_5F00_thumb_5F00_6789C77F.png" border="0"></a>
</p><p>This happens when they do a pointer-over on the button! </p><p>They asked for GREEN buttons, and this is certainly not one! They want a lighter shade of green when there is a pointer-over. (Or cornflower blue, perhaps? Fight Club?)</p><p>&nbsp;</p><p>This is probably an overly simplified scenario, but is a good place to start. So let’s see how Visual States can help, and why it’s a good idea to create a style for this instead of just setting the background to some color and call it a day.</p><p>&nbsp;</p><h2>Blend is good at handling Visual States!</h2><p>Open the project in Blend for Visual Studio 2012, and right-click on the button, go to edit templates, and select “Edit a copy”.</p><p>&nbsp;</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8308.image_5F92251D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8308.image_5F00_5F92251D.png"><img width="477" height="484" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8321.image_thumb_2F87D39C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8321.image_5F00_thumb_5F00_2F87D39C.png" border="0"></a>
</p><p></p><p>Go ahead and give it a name that makes sense, and you can choose where you want this Style to be created – i.e., at an application level, at a page level, or as a resource dictionary. I’ll select Application for now – so that we can use it in different pages in the app.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3515.image_619EFE19.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3515.image_5F00_619EFE19.png"><img width="394" height="243" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5756.image_thumb_670D6EBD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5756.image_5F00_thumb_5F00_670D6EBD.png" border="0"></a>
</p><p>Once this is done, you should see something like this:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0042.image_0577AFA7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0042.image_5F00_0577AFA7.png"><img width="269" height="186" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8054.image_thumb_5CF8CD92.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8054.image_5F00_thumb_5F00_5CF8CD92.png" border="0"></a>
</p><p>1. You see that you are now working in App.xaml, and</p><p>2. You see that you are editing the template of the button.</p><p>Now, head over to the “States” panel in Blend, and you should see something like this:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2273.image_496B6DF1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2273.image_5F00_496B6DF1.png"><img width="324" height="325" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8358.image_thumb_5A0368DF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8358.image_5F00_thumb_5F00_5A0368DF.png" border="0"></a>
</p><p>Notice that we have all the states that a button can be in – normal, pressed, disabled, pointer over. </p><p>Notice that the button also has <strong>2 state groups</strong>. A state group is a group of <strong>mutually exclusive states</strong> that a control can be in at a given time. In other words, a button can be in a “Normal” state <strong>OR</strong> a “Pressed” (or other) state at a given time, but <strong>NOT both</strong>. However, the control can be in “Focused” state <strong>AND</strong> “PointerOver” at the same time, because they are in different state groups.</p><p>Great – it should be fairly obvious what we should do next, but a quick note on the color in the normal state. Notice that you had set the background of the button to green? That shows in the “border background” when you click on the “Normal” state.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6864.image_6A9B63CD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6864.image_5F00_6A9B63CD.png"><img width="644" height="273" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5488.image_thumb_35422B9B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5488.image_5F00_thumb_5F00_35422B9B.png" border="0"></a>
</p><p>&nbsp;</p><p>Notice the yellow button next to the Background? Whenever you see that little button next to a property turned yellow, it means it’s bound to something. It could either be a data binding or a template binding. In this case, as we’re editing a template, the border’s background has template binding to the “Background” property of the button. So when you set the background of the button, it also sets the background of the border, which is part of what the button is made up of. (You can also see that the border’s “Border Thickness” is also template bound to the border thickness of the button.)</p><p>Since we’re creating a “GreenButtonStyle”, let’s not have this template binding on the border’s background!</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0676.image_03F3413B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0676.image_5F00_03F3413B.png"><img width="352" height="285" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3716.image_thumb_4F726EF2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3716.image_5F00_thumb_5F00_4F726EF2.png" border="0"></a>
</p><p>Click on the tiny yellow button and click on reset to remove the template binding. That should throw a nice, scary message like this!</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1541.image_33ED6CEF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1541.image_5F00_33ED6CEF.png"><img width="608" height="153" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1145.image_thumb_5D15052D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1145.image_5F00_thumb_5F00_5D15052D.png" border="0"></a>
</p><p><em>Oh no oh no oh no!!</em></p><p>Nah, don’t worry about it – we’ll deal with these animations soon enough.</p><p>Let’s go ahead and select that nice green color we chose earlier. </p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1205.image_08E5591D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1205.image_5F00_08E5591D.png"><img width="351" height="405" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0121.image_thumb_73A72DA7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0121.image_5F00_thumb_5F00_73A72DA7.png" border="0"></a>
</p><p>Notice that this time around, the tiny button is not yellow! (It used to be called Advanced Options, but calling it tiny button is more fun!) When it’s not yellow, it’s a local value and does not depend on a binding.</p><p>&nbsp;</p><p>Now, select the “PointerOver” state and change the border background to a lighter shade.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1777.image_54A10A09.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1777.image_5F00_54A10A09.png"><img width="644" height="259" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8512.image_thumb_780D88A1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8512.image_5F00_thumb_5F00_780D88A1.png" border="0"></a>
</p><p>And that’s pretty much it. Let’s run this app:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3806.image_5B43EDBF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3806.image_5F00_5B43EDBF.png"><img width="145" height="87" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2313.image_thumb_1A356E5B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2313.image_5F00_thumb_5F00_1A356E5B.png" border="0"></a>
<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4382.image_071441AF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4382.image_5F00_071441AF.png"><img width="145" height="87" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0741.image_thumb_6A2B1CD9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0741.image_5F00_thumb_5F00_6A2B1CD9.png" border="0"></a>
</p><p>That’s a lot closer to what the customer wants!</p><p>Hey, what about all those “animations” Blend warned me about?</p><p>If you switch over to the “Code” view in Blend, you’ll see that all the states which has some property change is actually part of a Storyboard and is of type ObjectAnimationUsingKeyFrames. This is what Blend was warning us about when we reset the value of the border’s background.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1727.image_04F742E6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1727.image_5F00_04F742E6.png"><img width="644" height="208" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7288.image_thumb_53A85885.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7288.image_5F00_thumb_5F00_53A85885.png" border="0"></a>
</p><p></p><p>I guess now it makes a lot more sense when you look back at what we did to <a href="http://blogs.msdn.com/b/amar/archive/2012/10/08/handling-different-orientations-and-views-with-windows-store-apps.aspx" target="_blank">handle the different views and orientation</a>. All we did was manipulate Visual States that correspond to the actual state of the page!</p><p>&nbsp;</p><p>Go ahead and try handling the different Visual States of the different controls that you use and would like to have a custom theme applied to them!</p><p>As you can see, Visual States give a much better control over the controls we want to customize! :)</p><p>&nbsp;<p>Thanks for reading and happy coding!<p>Amar<p>&nbsp;<p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>Hello world, with Knockout JS and ASP.NET MVC 4!</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/hello-world-with-knockout-js-and-asp-net-mvc-4</link>
      <pubDate>Tue, 11 Dec 2012 13:03:00 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2012/12/11/hello-world-with-knockout-js-and-asp-net-mvc-4/</guid>
      <description><![CDATA[I heard about Knockout a few months ago, but never gave it a proper try &ndash; at least not with...]]></description>
      <content:encoded><![CDATA[<p>I heard about <a href="http://knockoutjs.com/" target="_blank">Knockout</a> a few months ago, but never gave it a proper try &ndash; at least not with ASP.NET MVC. You&rsquo;ll enjoy the ViewModel pattern if you don&rsquo;t want to have any code on your View &ndash; be it JS or CS! You can have a clean markup and a separate most part of the code that might be required to make it work. You&rsquo;ll probably relate to it the best if you have some experience working with a XAML based UI technology (WPF/SL/Windows 8), but that&rsquo;s not a prerequisite.</p>
<p>I played around a bit with the Knockout <a href="http://learn.knockoutjs.com/" target="_blank">tutorials</a> which gave a fair idea of how to go about using it.</p>
<p>However, it was difficult to find a &ldquo;hello world&rdquo; sample for using Knockout with ASP.NET MVC 4 which was simple enough to follow.</p>
<p>Here is my shot at it!</p>
<p>I&rsquo;m using ASP.NET Web API along with MVC 4 and Knockout to write a simple program that reads some data from the server and posts new data back to the server which will be persisted on a database.</p>
<p>&nbsp;</p>
<p>If you haven&rsquo;t installed ASP.NET MVC 4, you can do so from <a href="http://www.asp.net/mvc" target="_blank">here</a>. You can install ASP.NET MVC 4 with VS 2010 too, so really &ndash; give it a try!</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7532.image_6859DFE9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7532.image_5F00_6859DFE9.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4606.image_thumb_74E78D05.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4606.image_5F00_thumb_5F00_74E78D05.png" alt="image" width="644" height="162" border="0" /></a></p>
<p>&nbsp;</p>
<p>Once you have ASP.NET MVC 4 installed, create a new project and select &ldquo;Internet application&rdquo;. One of the things you&rsquo;ll notice is it adds a number of <a href="http://nuget.org/" target="_blank">NuGet</a> packages by default. One of them is KnockoutJS.</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2211.image_4BFC77FC.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2211.image_5F00_4BFC77FC.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6332.image_thumb_231162F3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6332.image_5F00_thumb_5F00_231162F3.png" alt="image" width="644" height="81" border="0" /></a></p>
<p>If you&rsquo;d rather start with an &ldquo;Empty application&rdquo;, you can add this package using the &ldquo;Manage NuGet Packages&rdquo; option when you right-click on the references.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1033.image_7A264DE9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1033.image_5F00_7A264DE9.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7571.image_thumb_0DD3377E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7571.image_5F00_thumb_5F00_0DD3377E.png" alt="image" width="335" height="147" border="0" /></a></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0121.image_5EA14BE6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0121.image_5F00_5EA14BE6.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4403.image_thumb_49632071.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4403.image_5F00_thumb_5F00_49632071.png" alt="image" width="644" height="431" border="0" /></a></p>
<p>&nbsp;</p>
<p>Now that we have Knockout, let&rsquo;s start!</p>
<h6>Here&rsquo;s what we&rsquo;ll do:</h6>
<ul>
<li>Create a simple database with just 1 table.</li>
<li>Create an EF model for this database.</li>
<li>Create a Web API controller to expose HTTP services which serves/accepts data.</li>
<li>Consume these HTTP services from the MVC views (Razor pages, although it could just be HTML pages too)</li>
<ul>
<li>Create a partial control for displaying data we get from the service</li>
<li>Create a partial control for creating a new item and posting it to the service.</li>
</ul>
</ul>
<p>We&rsquo;ll create the 2 partial views, but host it in a single razor page that will be served as a result of an action. This is to demonstrate how we can set the &ldquo;data context&rdquo; of individual HTML nodes with Knockout, so that&rsquo;ll be fun!</p>
<p>&nbsp;</p>
<h3>Create a simple database</h3>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8524.image_3424F4FC.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8524.image_5F00_3424F4FC.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4370.image_thumb_54E8B7E3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4370.image_5F00_thumb_5F00_54E8B7E3.png" alt="image" width="644" height="364" border="0" /></a></p>
<p>I don&rsquo;t need to say much about this I guess.</p>
<p>&nbsp;</p>
<h3>Create an EF model</h3>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4466.image_38F782EB.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4466.image_5F00_38F782EB.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4454.image_thumb_4CA46C7F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4454.image_5F00_thumb_5F00_4CA46C7F.png" alt="image" width="202" height="244" border="0" /></a></p>
<p>Once we have the EF model created, let&rsquo;s add a couple of static methods to make it easier to talk to the model:</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">namespace</span> KnockOutDemo.Models</pre>
<pre>{</pre>
<pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> CustomerRepository</pre>
<pre>    {</pre>
<pre class="alt">        <span class="kwrd">public</span> <span class="kwrd">static</span> IEnumerable&lt;Customer&gt; GetCustomers()</pre>
<pre>        {</pre>
<pre class="alt">            var myDB = <span class="kwrd">new</span> CustomerDBEntities();</pre>
<pre>            var query = from cust <span class="kwrd">in</span> myDB.Customers</pre>
<pre class="alt">                        select cust;</pre>
<pre>&nbsp;</pre>
<pre class="alt">            <span class="kwrd">return</span> query.ToList();</pre>
<pre>        }</pre>
<pre class="alt">&nbsp;</pre>
<pre>        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> InsertCustomer(Customer cust)</pre>
<pre class="alt">        {</pre>
<pre>            var myDB = <span class="kwrd">new</span> CustomerDBEntities();</pre>
<pre class="alt">            myDB.Customers.Add(cust);</pre>
<pre>            myDB.SaveChanges();</pre>
<pre class="alt">        }</pre>
<pre>    }</pre>
<pre class="alt">}</pre>
</div>
<p>&nbsp;</p>
<h3>Create a Web API controller to expose HTTP services which serves/accepts data</h3>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7673.image_1D064DF3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7673.image_5F00_1D064DF3.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7673.image_thumb_2993FB0F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7673.image_5F00_thumb_5F00_2993FB0F.png" alt="image" width="608" height="397" border="0" /></a></p>
<p>&nbsp;</p>
<p>Let&rsquo;s add the following code to get started with Get and Post methods:</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">public</span> <span class="kwrd">class</span> CustomerController : ApiController</pre>
<pre>{</pre>
<pre class="alt">        <span class="rem">// GET api/customer</span></pre>
<pre>        <span class="kwrd">public</span> IEnumerable&lt;Customer&gt; Get()</pre>
<pre class="alt">        {</pre>
<pre>            var cust = CustomerRepository.GetCustomers();</pre>
<pre class="alt">            <span class="kwrd">return</span> cust.ToList();</pre>
<pre>        }</pre>
<pre class="alt">&nbsp;</pre>
<pre>        <span class="rem">// GET api/customer/5</span></pre>
<pre class="alt">        <span class="kwrd">public</span> Customer Get(<span class="kwrd">int</span> id)</pre>
<pre>        {</pre>
<pre class="alt">            <span class="kwrd">return</span> CustomerRepository.GetCustomers().Where((c) =&gt; c.Id == id).FirstOrDefault();</pre>
<pre>        }</pre>
<pre class="alt">&nbsp;</pre>
<pre>        <span class="rem">// POST api/customer</span></pre>
<pre class="alt">        <span class="kwrd">public</span> HttpResponseMessage Post(Customer <span class="kwrd">value</span>)</pre>
<pre>        {</pre>
<pre class="alt">            CustomerRepository.InsertCustomer(<span class="kwrd">value</span>);</pre>
<pre>&nbsp;</pre>
<pre class="alt">            var response = Request.CreateResponse&lt;Customer&gt;(HttpStatusCode.Created, <span class="kwrd">value</span>);</pre>
<pre>&nbsp;</pre>
<pre class="alt">            <span class="kwrd">string</span> uri = Url.Link(<span class="str">"DefaultApi"</span>, <span class="kwrd">new</span> { id = <span class="kwrd">value</span>.Id });</pre>
<pre>            response.Headers.Location = <span class="kwrd">new</span> Uri(uri);</pre>
<pre class="alt">&nbsp;</pre>
<pre>            <span class="kwrd">return</span> response;</pre>
<pre class="alt">        }</pre>
<pre>}</pre>
</div>
<p>&nbsp;</p>
<h3>Consume these HTTP services from the MVC views</h3>
<p>Let&rsquo;s add a View page to the Home folder called Customers, which basically acts as a shell. We&rsquo;ll have a couple of place holders in this view which will host a partial view for displaying a list of customers and another partial view for letting the user create a new customer.</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3438.image_7342D2FF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3438.image_5F00_7342D2FF.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5670.image_thumb_3F9A66A1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5670.image_5F00_thumb_5F00_3F9A66A1.png" alt="image" width="644" height="110" border="0" /></a></p>
<p>Also create an appropriate action method in the HomeController.cs file:</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">public</span> ActionResult Customers()</pre>
<pre>{</pre>
<pre class="alt">      <span class="kwrd">return</span> View();</pre>
<pre>}</pre>
</div>
<p>Now, let&rsquo;s add the 2 partial views &ndash; CustomerList and CreateCustomer. I have created these in the Shared folder, but could&rsquo;ve done so in the Home folder as well.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1778.image_28F8185A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1778.image_5F00_28F8185A.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2330.image_thumb_0D731657.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2330.image_5F00_thumb_5F00_0D731657.png" alt="image" width="488" height="484" border="0" /></a></p>
<p>These would basically be blank cshtml pages.</p>
<p>Add this markup to the CustomerList.cshtml page:</p>
<p>&nbsp;</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">&lt;</span><span class="html">table</span> <span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 2: </span>    <span class="kwrd">&lt;</span><span class="html">thead</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 3: </span>        <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 4: </span>            <span class="kwrd">&lt;</span><span class="html">th</span><span class="kwrd">&gt;</span>Id<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 5: </span>            <span class="kwrd">&lt;</span><span class="html">th</span><span class="kwrd">&gt;</span>Name<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 6: </span>            <span class="kwrd">&lt;</span><span class="html">th</span><span class="kwrd">&gt;</span>Age<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 7: </span>            <span class="kwrd">&lt;</span><span class="html">th</span><span class="kwrd">&gt;</span>Comments<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 8: </span>        <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 9: </span>    <span class="kwrd">&lt;/</span><span class="html">thead</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 10: </span>    <span class="kwrd">&lt;</span><span class="html">tbody</span> <span class="attr">data-bind</span><span class="kwrd">="foreach: customers"</span> <span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 11: </span>        <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 12: </span>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">data-bind</span><span class="kwrd">="text: Id"</span><span class="kwrd">&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 13: </span>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">data-bind</span><span class="kwrd">="text: Name"</span><span class="kwrd">&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 14: </span>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">data-bind</span><span class="kwrd">="text: Age"</span><span class="kwrd">&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 15: </span>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">data-bind</span><span class="kwrd">="text: Comments"</span><span class="kwrd">&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 16: </span>        <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 17: </span>    <span class="kwrd">&lt;/</span><span class="html">tbody</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 18: </span><span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 19: </span><span class="kwrd">&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span></pre>
<pre><span class="lnum"> 20: </span><span class="kwrd">&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="button"</span> <span class="attr">id</span><span class="kwrd">="btnGetCustomers"</span> <span class="attr">value</span><span class="kwrd">="Get Customers"</span> <span class="attr">data-bind</span><span class="kwrd">="click: getCustomers"</span> <span class="kwrd">/&gt;</span></pre>
</div>
<p>Notice the markup on line 10, line 20 and lines 12 through 15. We are using a new attribute: <strong>data-bind</strong>.</p>
<p>In the line 10, we&rsquo;re mentioning a foreach on the &ldquo;customers&rdquo; collection (that we just assume will be present at runtime), and for each of those customers, we generate a row in the table.</p>
<p>Lines 12-15 bind the properties of each customer to the text attribute of the td.</p>
<p>Similarly, we&rsquo;re binding the &ldquo;click&rdquo; event of input to call the getCustomers method (again we assume this will be present at runtime). You can set multiple bindings too within a data-bind expression, but we&rsquo;ll not get into that right now.</p>
<p>I&rsquo;d like to emphasize on the fact that the <strong>markup over here is just markup</strong> &ndash; <strong>no code</strong>.</p>
<p>Add this markup to the CreateCustomer.cshtml page:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">&lt;</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 2: </span>    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 3: </span>        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>Name<span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 4: </span>        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="text"</span> <span class="attr">data-bind</span><span class="kwrd">="value: Name"</span> <span class="kwrd">/&gt;</span> <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 5: </span>    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 6: </span>    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 7: </span>        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>Age<span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 8: </span>        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="text"</span> <span class="attr">data-bind</span><span class="kwrd">="value: Age"</span> <span class="kwrd">/&gt;</span> <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 9: </span>    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 10: </span>    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 11: </span>        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>Comments<span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 12: </span>        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="text"</span> <span class="attr">data-bind</span><span class="kwrd">="value: Comments"</span> <span class="kwrd">/&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 13: </span>    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
<pre><span class="lnum"> 14: </span><span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum"> 15: </span>&nbsp;</pre>
<pre><span class="lnum"> 16: </span><span class="kwrd">&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="button"</span>  <span class="attr">value</span><span class="kwrd">="Add"</span> <span class="attr">data-bind</span><span class="kwrd">="click: addCustomer"</span> <span class="kwrd">/&gt;</span></pre>
</div>
<p>We follow the same approach as earlier here.</p>
<p>At this point, we have the View ready and the HTTP service is up and running.</p>
<p>Let&rsquo;s create the ViewModel and see how we can bring all of this together!</p>
<p>From the two partial views, it&rsquo;s clear that we can use two ViewModels &ndash; one for creating a customer (and therefore, a customer object) and another one for listing all the customers (something that holds a collection of customers).</p>
<p>To get started, create a folder in the project, say MyJS, and add a new .js file:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5164.image_12755406.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5164.image_5F00_12755406.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0842.image_thumb_641BCE58.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0842.image_5F00_thumb_5F00_641BCE58.png" alt="image" width="217" height="42" border="0" /></a></p>
<p>Drag and drop the jquery script and knockoutjs scripts to this the CustomerViewModel.js file in the editor.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3404.image_7181E15E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3404.image_5F00_7181E15E.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7128.image_thumb_50223BC2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7128.image_5F00_thumb_5F00_50223BC2.png" alt="image" width="313" height="388" border="0" /></a></p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0434.image_2EC29626.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0434.image_5F00_2EC29626.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3554.image_thumb_349D39BF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3554.image_5F00_thumb_5F00_349D39BF.png" alt="image" width="615" height="99" border="0" /></a></p>
<p>This only helps us with the intellisense, we&rsquo;ll have to reference the jQuery and KnockoutJS files later in the view.</p>
<p>&nbsp;</p>
<p>Next, add this code to the CustomerViewModel.js file:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">function</span> customer(id, name, age, comments) {</pre>
<pre><span class="lnum"> 2: </span>    <span class="kwrd">var</span> self = <span class="kwrd">this</span>;</pre>
<pre class="alt"><span class="lnum"> 3: </span>&nbsp;</pre>
<pre><span class="lnum"> 4: </span>    self.Id = id;</pre>
<pre class="alt"><span class="lnum"> 5: </span>    self.Name = name;</pre>
<pre><span class="lnum"> 6: </span>    self.Age = age,</pre>
<pre class="alt"><span class="lnum"> 7: </span>    self.Comments = comments;</pre>
<pre><span class="lnum"> 8: </span>&nbsp;</pre>
<pre class="alt"><span class="lnum"> 9: </span>    self.addCustomer = <span class="kwrd">function</span> () {</pre>
<pre><span class="lnum"> 10: </span>        $.ajax({</pre>
<pre class="alt"><span class="lnum"> 11: </span>            url: <span class="str">"/api/customer/"</span>,</pre>
<pre><span class="lnum"> 12: </span>            type: <span class="str">'post'</span>,</pre>
<pre class="alt"><span class="lnum"> 13: </span>            data: ko.toJSON(<span class="kwrd">this</span>),</pre>
<pre><span class="lnum"> 14: </span>            contentType: <span class="str">'application/json'</span>,</pre>
<pre class="alt"><span class="lnum"> 15: </span>            success: <span class="kwrd">function</span> (result) {</pre>
<pre><span class="lnum"> 16: </span>            }</pre>
<pre class="alt"><span class="lnum"> 17: </span>        });</pre>
<pre><span class="lnum"> 18: </span>    }</pre>
<pre class="alt"><span class="lnum"> 19: </span>}</pre>
</div>
<p>&nbsp;</p>
<p>Although we&rsquo;re creating a function here, you can think of this as something similar to creating a ViewModel class with XAML.</p>
<p>With the customer object, we have the 4 properties that we have bound to from our UI. Since we&rsquo;re going to use this as the ViewModel for the CreateCustomer partial view, we are also going to create a function called addCustomer which does a POST to the HTTP service we created earlier. The data that we&rsquo;re posting is conveniently obtained by using the ko.toJSON() method.</p>
<p>Similarly, create the ViewModel that we can use to contain the list of all customers. For a lack of better name, I just called it customerVM!</p>
<p>Add the following code to the CustomerViewModel.js file:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">function</span> customerVM() {</pre>
<pre><span class="lnum"> 2: </span>    <span class="kwrd">var</span> self = <span class="kwrd">this</span>;</pre>
<pre class="alt"><span class="lnum"> 3: </span>    self.customers = ko.observableArray([]);</pre>
<pre><span class="lnum"> 4: </span>    self.getCustomers = <span class="kwrd">function</span> () {</pre>
<pre class="alt"><span class="lnum"> 5: </span>        self.customers.removeAll();</pre>
<pre><span class="lnum"> 6: </span>        $.getJSON(<span class="str">"/api/customer/"</span>, <span class="kwrd">function</span> (data) {</pre>
<pre class="alt"><span class="lnum"> 7: </span>            $.each(data, <span class="kwrd">function</span> (key, val) {</pre>
<pre><span class="lnum"> 8: </span>                self.customers.push(<span class="kwrd">new</span> customer(val.Id, val.Name, val.Age, val.Comments));</pre>
<pre class="alt"><span class="lnum"> 9: </span>            });</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>
<p>On line 3, we are creating a list (array) of customers, but notice that this is not a simple array. It&rsquo;s an observableArray from the Knockout library! Which means, any changes to this array will result in automatic notifications to any UI elements that are bound to it! (You can compare this with an ObservableCollection from the C# world)</p>
<p>The rest is fairly self explanatory &ndash; we&rsquo;re doing a getJSON call to the HTTP service and getting the list of all customers and populating the customers observableArray. This is collection that we bound to in the CustomerList.cshtml&rsquo;s tbody tag: <span class="kwrd">&lt;</span><span class="html">tbody</span> <span class="attr">data-bind</span><span class="kwrd">="foreach: customers"</span><span class="kwrd">&gt;</span></p>
<p><span class="kwrd">The only thing pending now is to somehow connect these ViewModels with the Views. Kinda like setting the DataContext of the UI elements if you are from the XAML world.</span></p>
<p><span class="kwrd">We can do this using the ko.applyBindings() method. We can either just specify the ViewModel for the entire view or set the ViewModel to a specific node in the DOM. </span></p>
<p><span class="kwrd">In our case, we&rsquo;ll specify the ViewModels for each of the partial views, by specifying the Id&rsquo;s of the div tags that we used in the Customers.cshtml file.</span></p>
<p>Add the following code to the CustomerViewModel.js file:</p>
<div class="csharpcode">
<pre class="alt">$(document).ready(<span class="kwrd">function</span> () {</pre>
<pre>    ko.applyBindings(<span class="kwrd">new</span> customerVM(), document.getElementById(<span class="str">'displayNode'</span>));</pre>
<pre class="alt">    ko.applyBindings(<span class="kwrd">new</span> customer(), document.getElementById(<span class="str">'createNode'</span>));</pre>
<pre>});</pre>
</div>
<p>Now, we can just reference the js files (CustomerViewModel.js, jQuery and Knockout) in the Customers.cshtml file.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8741.image_1A5CD09B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8741.image_5F00_1A5CD09B.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8345.image_thumb_0A6D8BD7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8345.image_5F00_thumb_5F00_0A6D8BD7.png" alt="image" width="644" height="266" border="0" /></a></p>
<p>&nbsp;</p>
<p>Alternatively, you can use the <strong>bundling</strong> feature that comes with ASP.NET MVC 4!</p>
<p>Go to the App_Start folder and open the BundleConfig.cs file.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8321.image_68358050.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8321.image_5F00_68358050.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1376.image_thumb_45FD74CA.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1376.image_5F00_thumb_5F00_45FD74CA.png" alt="image" width="644" height="178" border="0" /></a></p>
<p>Add the following code:</p>
<div class="csharpcode">
<pre class="alt">bundles.Add(<span class="kwrd">new</span> ScriptBundle(<span class="str">"~/bundles/myBundle"</span>).Include(</pre>
<pre>                       <span class="str">"~/Scripts/jquery-{version}.js"</span>,</pre>
<pre class="alt">                       <span class="str">"~/Scripts/knockout-2.1.0.js"</span>,</pre>
<pre>                       <span class="str">"~/MyJS/CustomerViewModel.js"</span>));</pre>
</div>
<p>We can now refer to all the three js files with the handle: &ldquo;~/bundles/myBundle&rdquo;</p>
<p>Let&rsquo;s head back to the Customers.cshtml file and delete the references to the three scripts we added earlier, and replace it with this line:</p>
<p><strong>@Scripts.Render("~/bundles/myBundle")</strong></p>
<p>&nbsp;</p>
<p>And that&rsquo;s about it! We should be good to go. Run the app and key in &ldquo;home/customers&rdquo; in the address bar.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6330.image_23C56944.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6330.image_5F00_23C56944.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8080.image_thumb_0FCBD6AE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8080.image_5F00_thumb_5F00_0FCBD6AE.png" alt="image" width="644" height="443" border="0" /></a></p>
<p>&nbsp;</p>
<p>Let&rsquo;s add a few customers:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4572.image_602DB821.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4572.image_5F00_602DB821.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0447.image_thumb_736E6EC0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0447.image_5F00_thumb_5F00_736E6EC0.png" alt="image" width="644" height="382" border="0" /></a></p>
<p>And get the list of customers:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6712.image_43D05034.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6712.image_5F00_43D05034.png"><img style="display: inline;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6470.image_thumb_2923B41B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6470.image_5F00_thumb_5F00_2923B41B.png" alt="image" width="644" height="421" border="0" /></a></p>
<p>&nbsp;</p>
<h3>Show me the codez!</h3>
<p>You can <strong>download the complete sample</strong> from <a href="http://sdrv.ms/UyeMaF" target="_blank">here</a>.</p>
<p>&nbsp;</p>
<h3>Further reading</h3>
<p><a href="http://knockoutjs.com/" target="_blank">KnockoutJS home page</a></p>
<p><a href="http://knockoutjs.com/documentation/introduction.html" target="_blank">KnockoutJS documentation</a></p>
<p><a href="http://learn.knockoutjs.com/" target="_blank">KnockoutJS tutorials</a></p>
<p><a href="http://www.asp.net/web-api" target="_blank">ASP.NET Web API</a></p>
<p><a href="http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification" target="_blank">Bundling and Minification</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Thanks for reading!</p>
<p>Amar</p>
<p>&nbsp;</p>
<p>PS: You can follow me on twitter at &ldquo;_amarnit&rdquo;, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>The “Light” theme for Windows store apps</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/the-light-theme-for-windows-store-apps</link>
      <pubDate>Mon, 26 Nov 2012 04:19:22 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2012/11/26/the-light-theme-for-windows-store-apps/</guid>
      <description><![CDATA[I was recently talking to a developer working on a Windows store app and he said: “Dude, why the...]]></description>
      <content:encoded><![CDATA[<p>I was recently talking to a developer working on a Windows store app and he said: “Dude, why the dark background for the apps? Shouldn’t Windows 8 apps be a bit brighter and cheerful? I had to show a good amount of text in my app, so I ended up setting the background to white and foreground to black on the various UI elements and it’s awful! Buttons don’t work as expected, they disappear when I do a mouse-over!”</p><p>He was pretty frustrated and I could imagine many others potentially facing this issue.</p><p>The solution is surprisingly simple, though!</p><p>Open your App.xaml file and set the application’s “<strong>RequestedTheme</strong>” property to Light.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5238.image_137016A8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5238.image_5F00_137016A8.png"><img width="644" height="113" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3568.image_thumb_667AB3CC.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3568.image_5F00_thumb_5F00_667AB3CC.png" border="0"></a>
</p><p>And we’re done! </p><p>Undo all the hardcoded backgrounds and foregrounds on all the UI elements – leave them to the defaults and you’ll have a light background with dark UI elements!</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3162.image_76A67BC5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3162.image_5F00_76A67BC5.png"><img width="644" height="364" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5710.image_thumb_2276CFB5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5710.image_5F00_thumb_5F00_2276CFB5.png" border="0"></a>
</p><p>The <strong>light</strong> theme is generally recommended for apps with a <strong>lot of text</strong>.</p><p>&nbsp;</p><p>Thanks for reading!
<p>Amar
<p>&nbsp;<p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!</p>]]></content:encoded>
    </item>
    <item>
      <title>A non-traditional “Hello World” app with Windows 8</title>
      <link>https://docs.microsoft.com/archive/blogs/amar/a-non-traditional-hello-world-app-with-windows-8</link>
      <pubDate>Wed, 07 Nov 2012 18:09:56 GMT</pubDate>
      <dc:creator><![CDATA[Amar Nityananda]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amar/2012/11/07/a-non-traditional-hello-world-app-with-windows-8/</guid>
      <description><![CDATA[As developers, we start exploring any new platform/framework/language with a traditional “Hello...]]></description>
      <content:encoded><![CDATA[<p>As developers, we start exploring any new platform/framework/language with a traditional “Hello World” program. <p>Windows 8 is a re-imagined new OS, and so I thought let’s re-imagine the “Hello World” too. <a href="http://apps.microsoft.com/webpdp/en-US/app/consultant-jargon/4dff618a-6458-4916-b5cc-894bbf0356c9" target="_blank">Consultant Jargon</a> is my non-traditional version of “Hello World”.<p>Windows 8 store apps have a few things we need to keep in mind other than the new WinRT API set and the new language choices. These apps can run on a wide range of devices with different form factors and so, a considerable amount of thought must go into designing such apps.<p>Consultant Jargon focuses on getting these basics right – it scales well with any display resolution, handles different views (like snapped and portrait), follows (most of) the Modern UI principles including the tiles, splash screen etc., and implements the share charm.<p>Feature-wise, it generates random, geeky jargon like “Balanced Reciprocal Time-frame”, “Responsive Incremental Programming” which means nothing in reality, but sounds complex and deep! What’s more, you can share this jargon with apps like Mail, MetroTwit, FlipToast etc., to post it on Twitter/Facebook/LinkedIn to impress (or spook out) your friends :)<h5>Let’s Start (pun intended)</h5><p>Open VS 2012, and create a new Windows Store Blank App.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5734.image41_10EF7E56.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5734.image41_5F00_10EF7E56.png"><img width="644" height="394" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0458.image41_thumb_6B55DB27.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0458.image41_5F00_thumb_5F00_6B55DB27.png" border="0"></a>
</p><p>&nbsp;</p><p>Next, delete the MainPage.xaml and add a new “Basic Page”, and name it MainPage.xaml. (<a href="http://blogs.msdn.com/b/amar/archive/2012/10/08/handling-different-orientations-and-views-with-windows-store-apps.aspx" target="_blank">Why?</a>)</p><p>It’s not a big deal if you name it something else, or leave it as the default “BasicPage1.xaml”. We just need to ensure that we update some code that runs when your app is launched which points to the first screen that the app should show.</p><p>So, if you choose not to name the new page as “MainPage.xaml”, just go to the App.xaml.cs file and navigate to the OnLaunched method. The Solution Explorer in the new VS 2012 helps you get there easily!</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7317.image8_7100CF00.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7317.image8_5F00_7100CF00.png"><img width="644" height="208" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3187.image8_thumb_4BD35EC7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3187.image8_5F00_thumb_5F00_4BD35EC7.png" border="0"></a></p><p>&nbsp;</p><p>Scroll down a bit and you should see this block of code, just before the OnLaunched method ends:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3568.image151_42B6AD79.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3568.image151_5F00_42B6AD79.png"><img width="644" height="220" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4336.image151_thumb_65B6F91C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4336.image151_5F00_thumb_5F00_65B6F91C.png" border="0"></a>
</p><p>Notice the underlined part. This statement effectively means – try navigating to “MainPage” – and if the navigate method returns a “false”, throw an exception.</p><p>You can replace the “MainPage” with the name of the Basic Page that you just created.</p><p>Cool! Now we have a base to start with that <a href="http://blogs.msdn.com/b/amar/archive/2012/10/08/handling-different-orientations-and-views-with-windows-store-apps.aspx" target="_blank">handles different orientations and views well</a>.</p><h5>To-Dos</h5><p>Here’s what we’ll do in our app now:</p><ul><li>Have a logo and title, and make sure that both are visible in the Full screen and Filled view, and only the logo is visible in the Snapped view.</li><li>Create a Splash Screen, which looks similar to the ones that comes with apps like the Messaging or Email app.</li><li>Create a tile which looks decent, both small and wide tile, and see how we can disable the text being shown on the tile.</li><li>Implement the “share” charm so that we can spread more non-sense around :D</li></ul><h6>Logo and title</h6><p>We have a few options to pick from to create our logo. You can find a good icon/logo on the web (just make sure it’s under an open license like Creative Commons).</p><p>Or, you can use one of the free tools to create a unique logo for yourself.</p><p>I used <a href="http://www.getpaint.net/" target="_blank">Paint.NET</a> and PowerPoint (for shapes) to create the Consultant Jargon Logo:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8053.Logo310_13E0CF0A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8053.Logo310_5F00_13E0CF0A.png"><img width="244" height="120" title="Logo310" style="display: inline;" alt="Logo310" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6283.Logo310_thumb_4A6E7A4E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6283.Logo310_5F00_thumb_5F00_4A6E7A4E.png" border="0"></a>
</p><p>Another great alternative is <a href="http://www.gimp.org/" target="_blank">GIMP</a>.</p><p>The main reason to go for these tools instead of, say MS Paint, is that we can create layers which helps in editing the images and save images with transparent backgrounds. And transparent backgrounds can be helpful, as we’ll see shortly.</p><p>Once I have the logo ready, I can use it to brand my app in the different views, and I can also scale it to different resolutions and use if for the tiles.</p><p>To use this logo in the main screen (and the only screen) in our app, we replace the “back button” with the logo.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2086.image4_568FF475.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2086.image4_5F00_568FF475.png"><img width="644" height="280" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4743.image4_thumb_18D2E6EC.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4743.image4_5F00_thumb_5F00_18D2E6EC.png" border="0"></a>
</p><p>&nbsp;</p><p>Let’s see if this shows up when we run the app. Sure enough, it does.</p><p>Now, let’s see how it handles the snapped view! (If you’re a keyboard person, Windows key + . )</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0027.image12_469089E4.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0027.image12_5F00_469089E4.png"><img width="644" height="364" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2577.image12_thumb_6E26E041.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2577.image12_5F00_thumb_5F00_6E26E041.png" border="0"></a>
</p><p></p><p>Right! Back Button. References. Tool generated code.</p><p>The reason why this exception shows up is that we sure replaced the “back button”, but didn’t handle other parts of the “Basic Page” that we added that references this back button. The “other parts” are the different visual states. So, scroll down in your main page to a section that starts with “&lt;VisualStateManager.VisualStateGroups&gt;”</p><p>Comment out (or delete) the sections that manipulated any properties on the back button.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0027.image16_79AC77B3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0027.image16_5F00_79AC77B3.png"><img width="644" height="280" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5873.image16_thumb_060A7510.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5873.image16_5F00_thumb_5F00_060A7510.png" border="0"></a>
</p><p>There, that’s much better.</p><p>Next, let’s play around a bit with layouts so that when in full screen/fill view, it shows the logo and title, and only the logo when in snapped view.</p><p>To do this, the approach I take is to have a two grids – one for the snapped view and one for the other views.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2543.image20_03349A50.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2543.image20_5F00_03349A50.png"><img width="644" height="361" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/6765.image20_thumb_094BC11E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/6765.image20_5F00_thumb_5F00_094BC11E.png" border="0"></a>
</p><p>&nbsp;</p><p>To manage transitions between the two grids, we’ll use the Visual States that the Basic Page provides.</p><p>To do this easily, we can use the “Device” window. Press Ctrl+Q which will take you to the Quick Launch text box (on the top right of the VS window). Type in “Device” and you should be able to open the device window.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3323.image_24546A5F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3323.image_5F00_24546A5F.png"><img width="567" height="87" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0181.image_thumb_380153F3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0181.image_5F00_thumb_5F00_380153F3.png" border="0"></a>
</p><p>&nbsp;</p><p>Select the snapped view (the third button) from the “View” option and make sure that the Visual state is set to “Snapped”. Click on the Enable state recording option, select (click on) the grid named “SnapTitle” and set the visibility property to Visible.</p><p>Similarly, select the grid named “FullTitle” and set the visibility to Collapse (while making sure the Snapped state recording is on).</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3716.image28_08CF685C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3716.image28_5F00_08CF685C.png"><img width="644" height="274" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2146.image28_thumb_1CB8D525.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2146.image28_5F00_thumb_5F00_1CB8D525.png" border="0"></a>
</p><p>And that’s it – the logo and the title are taken care of in all the different views :)</p><p>&nbsp;</p><h5>Splash screen</h5><p>Splash screen is the first impression that you get to make on the user. And we all know first impression matters :) </p><p>That’s a good enough reason to invest in a good splash screen.</p><p>The image that we are allowed to use for a splash screen should be of 620 X 300 resolutions. But hey, what if my screen resolution is larger than that? Of course it’s going to be larger than that! :)</p><p>So how do I get this:</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5466.image36_055DAAE7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5466.image36_5F00_055DAAE7.png"><img width="644" height="364" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2630.image36_thumb_4EA04FE2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2630.image36_5F00_thumb_5F00_4EA04FE2.png" border="0"></a>
</p><p>It’s actually a combination of the splash screen image itself, along with a background color.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3617.image40_2CD47751.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3617.image40_5F00_2CD47751.png"><img width="644" height="113" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/7827.image40_thumb_5838984B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/7827.image40_5F00_thumb_5F00_5838984B.png" border="0"></a>
</p><p>So, <strong>avoid</strong> having <strong>gradients or high-res images</strong> that may abruptly cut off at 620 X 300 so that it can blend really well with the background color – and we should be good!</p><p>&nbsp;<img width="640" height="360" title="Screen shot 1" alt="Screen shot 1" src="http://wscont2.apps.microsoft.com/winstore/1x/7abf5ae3-fa8c-4194-9967-503d701156ca/Screenshot.34050.1000000.jpg"></p><h5>Invest in a good tile</h5><p>You would have heard about Live Tiles enough by now :)</p><p>It’s one of the most visible things that differentiates the UI on Windows 8 and Windows Phone from the rest.</p><p>But does every app need a Live Tile? Not necessarily. If you don’t have dynamic content to update your tile with, it’s OK not to have a Live Tile. But even if it’s a static tile, it’s always a good idea to have one that catches the eye. It’s good to have the brand associated with the tile.</p><p>With Windows 8, we have two options for tiles to be displayed on the start screen – a small tile and a large tile. The small tile is 150 X 150 pixels and the large tile is 310 X 150 pixels. The large tile is optional. There is another tile that is required which is the small logo – a 30 X 30 pixel image. This is what is displayed when you search for your app from the search charm.</p><p>Apart from these, there is another resolution image that we need to keep in mind <strong>for the Windows Store</strong> itself – and that’s a 50 X 50 pixel image.</p><p align="center">
</p><table width="600" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td width="150" valign="top"><p align="center">&nbsp;</p><p align="center">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3782.Logo310_6381AC88.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3782.Logo310_5F00_6381AC88.png"><img width="244" height="120" title="Logo310" style="display: inline;" alt="Logo310" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/0564.Logo310_thumb_212E9445.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/0564.Logo310_5F00_thumb_5F00_212E9445.png" border="0"></a></p></td><td width="150" valign="top"><p align="center"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5355.Logo150_3F2CA239.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5355.Logo150_5F00_3F2CA239.png"><img width="154" height="154" title="Logo150" style="display: inline;" alt="Logo150" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4375.Logo150_thumb_16418D30.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4375.Logo150_5F00_thumb_5F00_16418D30.png" border="0"></a></p></td><td width="150" valign="top"><p align="center">&nbsp;</p><p align="center">&nbsp;</p><p align="center">&nbsp;</p><p align="center">&nbsp;</p><p align="center"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1638.Logo50_427E1414.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1638.Logo50_5F00_427E1414.png"><img width="54" height="54" title="Logo50" style="display: inline;" alt="Logo50" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/2625.Logo50_thumb_4C63057F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/2625.Logo50_5F00_thumb_5F00_4C63057F.png" border="0"></a></p></td><td width="150" valign="top"><p align="center">&nbsp;</p><p align="center">&nbsp;</p><p align="center">&nbsp;</p><p align="center">&nbsp;</p><p align="center">&nbsp;</p><p align="center"><img width="34" height="34" title="logo30" style="display: inline;" alt="logo30" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8507.logo30_thumb_043549A3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8507.logo30_5F00_thumb_5F00_043549A3.png" border="0"></p></td>
</tr>
<tr>
<td width="150" valign="top"><p align="center">310 X 150 png</p></td><td width="150" valign="top"><p align="center">150 X 150 png</p></td><td width="150" valign="top"><p align="center">50 X 50 png</p></td><td width="150" valign="top"><p align="center">30 X 30 png</p></td>
</tr>
</tbody>
</table>
<p>I’ve seen a lot of people miss out the 30 pixel and 50 pixel logos and it would show up as the default logo (I like to call it the “Don’t do it” logo coz of the X in the image :) )</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1641.StoreLogo_49D9D3C1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1641.StoreLogo_5F00_49D9D3C1.png"><img width="54" height="54" title="StoreLogo" style="display: inline;" alt="StoreLogo" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5342.StoreLogo_thumb_68B0479F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5342.StoreLogo_5F00_thumb_5F00_68B0479F.png" border="0"></a>
</p><p><em>Don’t do it!</em></p><p>&nbsp;</p><h5>The Share Charm</h5><p>One of the really great things I liked about Windows 8 is how it lets our apps integrate to the core Windows experience. The Share Charm is one such way to provide the user a familiar experience for sharing content from your app with other apps (which most often boils down to sharing with people).</p><p>And, one of the most frequently asked question about this feature is “how’s it different from copy-paste?”</p><p>Well, you can present the data to be shared in a particular format.</p><p>In Consultant Jargon, I’m keeping it simple and adding a couple of words to the actual jargon as shown below.</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/1638.image_7C5D3133.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/1638.image_5F00_7C5D3133.png"><img width="644" height="364" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/5344.image_thumb_1EC19A22.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/5344.image_5F00_thumb_5F00_1EC19A22.png" border="0"></a>
</p><p>&nbsp;</p><p>The <a href="http://apps.microsoft.com/webpdp/en-us/app/wikipedia/6b80bf54-1a31-4651-acce-59a5b5c2b7c8" target="_blank">Wikipedia app</a> on the other hand, makes use of it in a beautiful way!</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/4760.image_0F2E6286.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/4760.image_5F00_0F2E6286.png"><img width="644" height="364" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/3683.image_thumb_5DFF0218.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/3683.image_5F00_thumb_5F00_5DFF0218.png" border="0"></a>
</p><p></p><p>In the above cases, Consultant Jargon and Wikipedia apps act as the Share Source, and the MetroTwit and Mail apps act as the Share Target.</p><p>Implementing the Share Target is a bit more involved, so I left it out of my little Hello World app :) Moreover it didn’t make much sense for this app to act as the target anyway!</p><p>Being a share source is extremely easy though, at least with simple formats like text and URLs. Use the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.datatransfermanager.getforcurrentview.aspx" target="_blank">DataTransferManager</a>!</p><p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8078.image_7EE24EF2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8078.image_5F00_7EE24EF2.png"><img width="644" height="269" title="image" style="display: inline;" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/33/metablogapi/8475.image_thumb_3FE0A88A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-33-metablogapi/8475.image_5F00_thumb_5F00_3FE0A88A.png" border="0"></a>
</p><p>That’s it and we’re good to spread non-sense around :)</p><p>&nbsp;</p><p>So, there we have it. A non-traditional Hello World to start off with developing apps for a re-imagined, new Windows 8.</p><p>&nbsp;</p><p>&nbsp;<p>Thanks for reading and happy coding!<p>Amar<p>&nbsp;<p>PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!<p>PPS: If you liked the &lt;Windows key + .&gt; shortcut for snapped view, you should check out my friend, Yash’s blog, for an <a href="http://blogs.msdn.com/b/hyperyash/archive/2012/08/28/windows-8-shortcuts.aspx" target="_blank">exhaustive list of Windows 8 Keyboard shortcuts</a>.]]></content:encoded>
    </item>
  </channel>
</rss>