<?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>John Socha-Leialoha's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/jsocha/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/jsocha/feed.xml</link>
    <description />
    <lastBuildDate>Tue, 16 Apr 2019 05:16:09 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Making a TextBlock in a DataTemplate Accessible</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/making-a-textblock-in-a-datatemplate-accessible</link>
      <pubDate>Tue, 20 Nov 2012 17:08:05 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2012/11/20/making-a-textblock-in-a-datatemplate-accessible/</guid>
      <description><![CDATA[I really love the data templates in XAML that allow me to create a XAML template for rendering an...]]></description>
      <content:encoded><![CDATA[<p>I really love the data templates in XAML that allow me to create a XAML template for rendering an object. This is particularly useful for <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.gridview.aspx">GridView</a> and other controls that can show the contents of a collection. I was recently working on the accessibility of our application, which allows screen readers to read the text on the screen. However, when we used <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.textblock.aspx">TextBlock</a> controls inside a <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.datatemplate.aspx">DataTemplate</a>, the screen reader wasn’t able to read the contents anymore. In this blog I’ll explain a little more about accessibility, and how to fix this problem.</p>  <p><strong>Update:</strong> 11/30/2012, I added a few more overrides to the automation peer to improve it’s behavior when used with the Narrator screen reader.</p>  <h2>Screen Readers</h2>  <p>If you’re running Windows 8 (and probably other versions as well), there is a program called Narrator that will convert screen text into spoken words, which allows someone who is blind to use a mouse. It’s pretty amazing technology, and I’m certainly not an expert on it. Supporting this ability is technology known as <a href="http://msdn.microsoft.com/en-us/library/ms747327.aspx">UI Automation</a>, which provides a way for developers to write programs that can look at the content on the screen. This system uses a provider model, with different sets of providers for different types of applications, including native C++, WPF, Web, and Windows Store applications.</p>  <h2>Inspecting the UI</h2>  <p>The <a href="http://msdn.microsoft.com/en-us/windows/hardware/hh852363.aspx">Windows Software Developers Kit (SDK) for Windows 8</a> (and a similar one for Windows 7 if I remember correctly) includes a program called <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd318521(v=vs.85).aspx">Inspect</a> that allows you to see the contents that are on your screen:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/41/35/metablogapi/0550.image_47E48CA0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0550.image_5F00_47E48CA0.png"><img title="image" style="border: 0px currentcolor; 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/41/35/metablogapi/3286.image_thumb_1C9FF599.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/3286.image_5F00_thumb_5F00_1C9FF599.png" width="550" height="444" /></a> </p>  <p>Here you can see that I’ve selected <strong>UI Automation Mode</strong> and <strong>Content View</strong> from the <strong>Options</strong> menu. Using these values mimics what a screen reader will see. I used this tool to figure out why my TextBlock controls weren’t being read by Narrator.</p>  <h2>Finding the Problem</h2>  <p>Here is how I found the problem. First, I selected <strong>Raw View</strong> in the <strong>Options</strong> menu. This will show everything, even elements that aren’t accessible to screen readers. I wanted to see what was different between these “hidden” elements and the “visible” ones. After some searching, I discovered the following properties in the right page of Inspect:</p>  <p><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/41/35/metablogapi/3034.image_436E0BD9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/3034.image_5F00_436E0BD9.png" width="231" height="36" /> </p>  <p>I’ve highlighted the property that made a difference: <strong>IsControlElement</strong>. My next question was “how do I set IsControlElement to true for TextBlock?”</p>  <h2>Making TextBlock Accessible</h2>  <p>After some searching in Bing, I found some references to overriding the protected <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.oncreateautomationpeer.aspx">OnCreateAutomationPeer</a> method of the TextBlock and returning a new automation peer instance that returns True from it’s <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.automation.peers.automationpeer.iscontrolelementcore.aspx">IsControlElementCore</a> method.</p>  <p>However, there was a problem: the Windows Store app version of TextBlock is marked sealed, so you can’t subclass it! The full WPF version of TextBlock is not marked sealed. So what can you do?</p>  <p>My solution was to create a new control that I call AccessibleTextBlock that I then use in place of the normal TextBlock control. I scratched my head about how best to do this and made some lucky guesses. In the end, it turned out not to be that hard. First, here is an example of using this new control:</p>  <div id="codeSnippetWrapper">   <pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ctls:AccessibleTextBlock</span><br />      <span style="color: rgb(255, 0, 0);">Text</span><span style="color: rgb(0, 0, 255);">=&quot;{Binding Name}&quot;</span><br />      <span style="color: rgb(255, 0, 0);">TextStyle</span><span style="color: rgb(0, 0, 255);">=&quot;{StaticResource BodyTextStyle}&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
</div>

<p>What’s the <strong>TextStyle</strong> property? It allows you to use styles targeted at TextBlock controls. You can’t apply such styles directly to this new AccessibleTextBlock because it doesn’t, and can’t, inherit from TextBlock. Hence, this property applies the style to the embedded TextBlock control.</p>

<h2>Creating the Control Template</h2>

<p>The AccessibleTextBlock control is a custom control, which means it has a XAML template you’ll need to add to your main resource dictionary. This template looks like this:</p>

<div id="codeSnippetWrapper">
  <pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Style</span> <span style="color: rgb(255, 0, 0);">TargetType</span><span style="color: rgb(0, 0, 255);">=&quot;ctls:AccessibleTextBlock&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Setter</span> <span style="color: rgb(255, 0, 0);">Property</span><span style="color: rgb(0, 0, 255);">=&quot;Template&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Setter.Value</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />            <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ControlTemplate</span> <span style="color: rgb(255, 0, 0);">TargetType</span><span style="color: rgb(0, 0, 255);">=&quot;ctls:AccessibleTextBlock&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />                <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">TextBlock</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">=&quot;Container&quot;</span> <br />                           <span style="color: rgb(255, 0, 0);">Text</span><span style="color: rgb(0, 0, 255);">=&quot;{TemplateBinding Text}&quot;</span><br />                           <span style="color: rgb(255, 0, 0);">TextTrimming</span><span style="color: rgb(0, 0, 255);">=&quot;{TemplateBinding TextTrimming}&quot;</span><br />                           <span style="color: rgb(255, 0, 0);">TextWrapping</span><span style="color: rgb(0, 0, 255);">=&quot;{TemplateBinding TextWrapping}&quot;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><br />            <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">ControlTemplate</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />        <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Setter.Value</span><span style="color: rgb(0, 0, 255);">&gt;</span><br />    <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Setter</span><span style="color: rgb(0, 0, 255);">&gt;</span><br /><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Style</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>

  <br />This is pretty simple. Most of the heavy lifting is done in the C# code. The C# code is a little longer than you might expect because it defines several dependency properties that are needed for supporting properties specific to the TextBlock control, such as TextTrimming. Here is the code:</div>

<div>&#160;</div>

<div></div>

<div>
  <pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><p><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">sealed</span> <span style="color: rgb(0, 0, 255);">class</span> AccessibleTextBlock : Control<br />{<br />    <span style="color: rgb(0, 0, 255);">public</span> AccessibleTextBlock()<br />    {<br />        <span style="color: rgb(0, 0, 255);">this</span>.DefaultStyleKey = <span style="color: rgb(0, 0, 255);">typeof</span>(TextBlock);<br />    }<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">string</span> Text<br />    {<br />        get { <span style="color: rgb(0, 0, 255);">return</span> (<span style="color: rgb(0, 0, 255);">string</span>)GetValue(TextProperty); }<br />        set { SetValue(TextProperty, <span style="color: rgb(0, 0, 255);">value</span>); }<br />    }<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> Style TextStyle<br />    {<br />        get { <span style="color: rgb(0, 0, 255);">return</span> (Style)GetValue(TextStyleProperty); }<br />        set { SetValue(TextStyleProperty, <span style="color: rgb(0, 0, 255);">value</span>); }<br />    }<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> TextTrimming TextTrimming<br />    {<br />        get { <span style="color: rgb(0, 0, 255);">return</span> (TextTrimming)GetValue(TextTrimmingProperty); }<br />        set { SetValue(TextTrimmingProperty, <span style="color: rgb(0, 0, 255);">value</span>); }<br />    }<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> TextWrapping TextWrapping<br />    {<br />        get { <span style="color: rgb(0, 0, 255);">return</span> (TextWrapping)GetValue(TextWrappingProperty); }<br />        set { SetValue(TextWrappingProperty, <span style="color: rgb(0, 0, 255);">value</span>); }<br />    }<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">readonly</span> DependencyProperty TextProperty =<br />        DependencyProperty.Register(<span style="color: rgb(0, 96, 128);">&quot;Text&quot;</span>, <span style="color: rgb(0, 0, 255);">typeof</span>(<span style="color: rgb(0, 0, 255);">string</span>), <span style="color: rgb(0, 0, 255);">typeof</span>(AccessibleTextBlock), <span style="color: rgb(0, 0, 255);">new</span> PropertyMetadata(String.Empty));<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">readonly</span> DependencyProperty TextWrappingProperty =<br />        DependencyProperty.Register(<span style="color: rgb(0, 96, 128);">&quot;TextWrapping&quot;</span>, <span style="color: rgb(0, 0, 255);">typeof</span>(TextWrapping), <span style="color: rgb(0, 0, 255);">typeof</span>(AccessibleTextBlock), <span style="color: rgb(0, 0, 255);">new</span> PropertyMetadata(TextWrapping.NoWrap));<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">readonly</span> DependencyProperty TextTrimmingProperty =<br />        DependencyProperty.Register(<span style="color: rgb(0, 96, 128);">&quot;TextTrimming&quot;</span>, <span style="color: rgb(0, 0, 255);">typeof</span>(TextTrimming), <span style="color: rgb(0, 0, 255);">typeof</span>(AccessibleTextBlock), <span style="color: rgb(0, 0, 255);">new</span> PropertyMetadata(TextTrimming.None));<br /><br />    <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">readonly</span> DependencyProperty TextStyleProperty =<br />        DependencyProperty.Register(<span style="color: rgb(0, 96, 128);">&quot;TextStyle&quot;</span>, <span style="color: rgb(0, 0, 255);">typeof</span>(Style), <span style="color: rgb(0, 0, 255);">typeof</span>(AccessibleTextBlock), <span style="color: rgb(0, 0, 255);">new</span> PropertyMetadata(<span style="color: rgb(0, 0, 255);">null</span>));<br /><br />    <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> AutomationPeer OnCreateAutomationPeer()<br />    {<br />        <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">new</span> TextBlockPeer(<span style="color: rgb(0, 0, 255);">this</span>);<br />    }<br /><br />    <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">void</span> OnApplyTemplate()<br />    {<br />        var child = GetTemplateChild(<span style="color: rgb(0, 96, 128);">&quot;Container&quot;</span>) <span style="color: rgb(0, 0, 255);">as</span> TextBlock;<br />        <span style="color: rgb(0, 0, 255);">if</span> (child != <span style="color: rgb(0, 0, 255);">null</span> &amp;&amp; TextStyle != <span style="color: rgb(0, 0, 255);">null</span>)<br />            child.Style = TextStyle;<br /><br />        <span style="color: rgb(0, 0, 255);">base</span>.OnApplyTemplate();<br />    }<br /><br />    <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">class</span> TextBlockPeer : FrameworkElementAutomationPeer<br />    {<br />        <span style="color: rgb(0, 0, 255);">public</span> TextBlockPeer(FrameworkElement owner)<br />            : <span style="color: rgb(0, 0, 255);">base</span>(owner)<br />        {<br />        }<br /><br />        <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">string</span> GetClassNameCore()<br />        {<br />            <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 96, 128);">&quot;TextBlockAccessable&quot;</span>;<br />        }<br /><br />        <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">string</span> GetLocalizedControlTypeCore()<br />        {<br />            <span style="color: rgb(0, 0, 255);">return</span> “text”;<br />        }<br /><br />        <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">string</span> GetNameCore()<br />        {<br />            <span style="color: rgb(0, 0, 255);">return</span> ((AccessibleTextBlock)Owner).Text;<br />        }<br /><br />        <span style="color: rgb(0, 0, 255);">protected</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">bool</span> IsControlElementCore()<br />        {<br />            <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">true</span>;<br />        }<br /><span style="color: rgb(0, 0, 255);"><br />        protected</span> <span style="color: rgb(0, 0, 255);">override</span> AutomationControlType GetAutomationControlTypeCore()<br />        {<br />            <span style="color: rgb(0, 0, 255);">return</span> AutomationControlType.Text;<br />        }<br /><br /><span style="color: rgb(0, 0, 255);">        protected</span> <span style="color: rgb(0, 0, 255);">override</span> IList&lt;AutomationPeer&gt; GetChildrenCore()<br />        {<br />            <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">null</span>;<br />        }<br />    }<br /></p></pre>
</div>

<div></div>

<div>There are a few tricks here. First, as I mentioned above, the main trick is to return a new automation peer that controls how screen readers view the AccessibleTextBlock control. Below you’ll find descriptions of why I needed to override various methods of the automation peer class:</div>

<div>&#160;</div>

<h4>GetNameCore</h4>

<p>Returns the text from the inner TextBlock control as the “Name” property of the control. Screen readers use this value as the text to read.</p>

<h4>IsControlElementCore</h4>

<p>This method must return true in order for the Narrator application to consider this a readable element.</p>

<h4>GetAutomationControlTypeCore</h4>

<p>By returning the type Text from this control, we tell the Narrator that this is a text control. For most controls, Narrator reads the text of the control, and then it reads the type of the control. The type is returned by GetLocalizedControlTypeCore. However, for text controls, Narrator only reads the text of the control and bypasses saying “text.” This override makes the AccessibleTextBlock control behave the same way.</p>

<h4>GetChildreCore</h4>

<p>Without overriding this method, applications like Inspect will show the child TextBlock. Returning null from this overridden method ensures that Inspect shows the AccessibleTextBlock as having no children, which makes it look more like a TextBlock control</p>

<div>I hope this is helpful to some of you. I certainly don’t guarantee that this solution is 100% correct (in fact, I would be surprised if it is). I did test this solution with the Narrator, and it worked perfectly.</div>]]></content:encoded>
    </item>
    <item>
      <title>Using the App Bar to Operate on Items</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/using-the-app-bar-to-operate-on-items</link>
      <pubDate>Thu, 25 Oct 2012 10:32:16 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2012/10/25/using-the-app-bar-to-operate-on-items/</guid>
      <description><![CDATA[I’m building a Windows Store App in C# and XAML, and I wanted to allow you to remove/edit/move items...]]></description>
      <content:encoded><![CDATA[<p>I’m building a Windows Store App in C# and XAML, and I wanted to allow you to remove/edit/move items in a GridView control, just like you can in the Finance application:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/41/35/metablogapi/0844.image_052F5C2A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0844.image_5F00_052F5C2A.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" 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/41/35/metablogapi/0447.image_thumb_28E883C4.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0447.image_5F00_thumb_5F00_28E883C4.png" width="550" height="309" /></a></p>  <p>When you right-click an item (or swipe down with touch), the item is selected (MSFT here) and the app bar pops up with commands that apply to this item. For whatever reason, I had a hard time finding an example of how to handle all these details. In the end, it turned out to be very simple—you just have to change several settings and add a little code. However, it took me some trial and error to get this to work.</p>  <h2>Setup the GridView Control</h2>  <p>The first step is to allow selection with the GridView control, which is disabled by default. You can enable selection with the following code:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">GridView</span><br />    <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;itemGridView&quot;</span><br />    <span style="color: #ff0000">AutomationProperties</span>.<span style="color: #ff0000">AutomationId</span><span style="color: #0000ff">=&quot;ItemGridView&quot;</span><br />    <span style="color: #ff0000">AutomationProperties</span>.<span style="color: #ff0000">Name</span><span style="color: #0000ff">=&quot;Grouped Items&quot;</span><br />    <span style="color: #ff0000">Grid</span>.<span style="color: #ff0000">RowSpan</span><span style="color: #0000ff">=&quot;2&quot;</span><br />    <span style="color: #ff0000">Padding</span><span style="color: #0000ff">=&quot;116,137,40,46&quot;</span><br />    <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">=&quot;{Binding Source={StaticResource groupedItemsViewSource}}&quot;</span><br />    <span style="color: #ff0000">ItemTemplate</span><span style="color: #0000ff">=&quot;{StaticResource Standard250x250ItemTemplate}&quot;</span><br />    <span style="color: #ff0000">SelectionMode</span><span style="color: #0000ff">=&quot;<font style="background-color: #ffff00">Multiple</font>&quot;</span><br />    <span style="color: #ff0000">IsSwipeEnabled</span><span style="color: #0000ff">=&quot;<font style="background-color: #ffff00">True</font>&quot;</span><br />    <span style="color: #ff0000">IsItemClickEnabled</span><span style="color: #0000ff">=&quot;True&quot;</span><br />    <span style="color: #ff0000">ItemClick</span><span style="color: #0000ff">=&quot;ItemView_ItemClick&quot;</span> <span style="color: #ff0000">SelectionChanged</span><span style="color: #0000ff">=&quot;<font style="background-color: #ffff00">itemGridView_SelectionChanged</font>&quot;</span><span style="color: #0000ff">&gt;</span></pre>

  <br /></div>

<p>I’ve changed two properties: <strong>SelectionMode</strong> and <strong>IsSwipeEnabled</strong> from what I got with the template for an Items Page. Setting <strong>SelectionMode</strong> to <strong>Multiple</strong> ensures several things. First, no items are initially selected, as they would be with single selection. Second, you can use the keyboard to move between item and then the space bar to select an item, which is the behavior that you’ll find in the Finance application.</p>

<p>You’ll also need to set <strong>IsSwipeEnabled</strong> to <strong>True</strong> to allow swiping down with your finger to select an item.</p>

<p>Finally, we need to receive the SelectionChanged event so our code can display the app bar whenever an item becomes selected.</p>

<h2>Showing the App Bar</h2>

<p>We want to display the app bar whenever an item becomes selected, whether from the keyboard (with space bar), the moue (right click), or swiping down with your finger: </p>

<div>
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> itemGridView_SelectionChanged(<span style="color: #0000ff">object</span> sender, SelectionChangedEventArgs e)<br />{<br />    <span style="color: #0000ff">if</span> (itemGridView.SelectedItem != <span style="color: #0000ff">null</span>)<br />        BottomAppBar.IsOpen = <span style="color: #0000ff">true</span>;<br />}</pre>
</div>

<div>&#160;</div>

<div>In other words, whenever you select an item, we show the app bar.</div>

<p>There is one final detail—when the app bar closes, you want to unselect any items. First, register to receive the Closed event for your app bar in your page’s constructor:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">this</span>.InitializeComponent();<br /><font style="background-color: #ffff00">BottomAppBar.Closed += BottomAppBar_Closed;</font></pre>

  <br /></div>

<p>Finally, here is the code to handle the closed event:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> BottomAppBar_Closed(<span style="color: #0000ff">object</span> sender, <span style="color: #0000ff">object</span> e)<br />{<br />    itemGridView.SelectedItem = <span style="color: #0000ff">null</span>;<br />}</pre>

  <br /></div>

<p>With these small changes, you can add commands to the app bar to operate on items in your page.</p>

<h2>Allowing Multiple Selections</h2>

<p>Without much more work, you can allow multiple selection. In this case,&#160; you can continue to select more items while the app bar is open. Supporting this requires a couple of small changes. First, you’ll want to change the app bar to be sticky, which you can do by adding the following to your page’s constructor:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">BottomAppBar.IsSticky = <span style="color: #0000ff">true</span>;</pre>

  <br /></div>

<p>This turns off the automatic closing of the app bar when you tap or click outside of the app bar.</p>

<p>Next, you’ll want to show the app bar as long as there are items selected, and hide it when there are no items selected. Change the code in your SelectionChanged event handler to read like this:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> itemGridView_SelectionChanged(<span style="color: #0000ff">object</span> sender, SelectionChangedEventArgs e)<br />{<br />    BottomAppBar.IsOpen = itemGridView.SelectedItems.Count &gt; 0;<br />}</pre>

  <br /></div>

<p>Now you can right click (or swipe down) to select an item, at which point the app bar appears. While the app bar is visible, you can right-click or swipe down to select more items.</p>

<h2>Dismissing The App Bar</h2>

<p>There are a couple more things to finish up the experience. When the app bar is visible, you can dismiss the app bar by left clicking (tapping) anywhere outside the app bar, or you can press the escape key. Here is the code you’ll need to handle those situations:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnTapped(TappedRoutedEventArgs e)<br />{<br />    <span style="color: #0000ff">base</span>.OnTapped(e);<br />    BottomAppBar.IsOpen = <span style="color: #0000ff">false</span>;<br />}<br /><br /><span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnKeyUp(KeyRoutedEventArgs e)<br />{<br />    <span style="color: #0000ff">base</span>.OnKeyUp(e);<br />    <span style="color: #0000ff">if</span> (e.Key == VirtualKey.Escape)<br />        BottomAppBar.IsOpen = <span style="color: #0000ff">false</span>;<br />}</pre>

  <br /></div>]]></content:encoded>
    </item>
    <item>
      <title>Building a Single-Select List in jQuery</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/building-a-single-select-list-in-jquery</link>
      <pubDate>Tue, 10 Jul 2012 10:57:58 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2012/07/10/building-a-single-select-list-in-jquery/</guid>
      <description><![CDATA[We needed a single-select list box for a web application we’re building. We also needed each item in...]]></description>
      <content:encoded><![CDATA[<p>We needed a single-select list box for a web application we’re building. We also needed each item in the list to have rich formatting, so we didn’t want to use the built-in list box. I knew that jQuery UI had a Selectable widget that looked very promising. However we didn’t want multi-selection or the other advanced features it provides. I was somewhat surprised when I did a search on Bing that I didn’t find any guidance on how to create a single-select list box with jQuery. However I did find enough hints. It turned out to be really simple. If I were a more experience web developer, I probably would have known all of this. This blog post is for people like me who aren’t web experts yet.</p>  <p>The solution involves adding a custom data- attribute to each item in the list, creating CSS entries for hover and selected, and writing a single jQuery method that handles updating the section. In the example below, I’m using data-query on HTML elements, like this:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">@foreach (Query query in Model)<br />{<br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">div</span> <span style="color: #ff0000">data-query</span><span style="color: #0000ff">=&quot;@query.Key&quot;</span><span style="color: #0000ff">&gt;</span>@query.Name<span style="color: #0000ff">&lt;/</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span><br />}</pre>

  <br /></div>



<h2>CSS Class</h2>

<p>Next I added some CSS to display different colors for hover and selected:</p>

<div id="codeSnippetWrapper">
  <div>
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">div</span>[data-query]:hover<br />{<br />    <span style="color: #0000ff">background-color</span>: <span style="color: #006080">#EEF;</span><br />    <span style="color: #0000ff">cursor</span>: <span style="color: #006080">pointer;</span><br />}<br /><br /><span style="color: #cc6633">.querySelected</span><br />{<br />    <span style="color: #0000ff">background-color</span>: <span style="color: #006080">#CCF;</span><br />}<br /></pre>
  </div>
</div>

<p>The first entry changes the color and mouse pointer for the entry under the mouse. It does this by selecting all div elements that contain the data-query attribute. The second entry is simply a class that we’ll apply to the “selected” element using some jQuery code.</p>

<h2>jQuery Code</h2>

<p>The following jQuery code is all that you need:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">$(<span style="color: #006080">&quot;[data-query]&quot;</span>).click(<span style="color: #0000ff">function</span> () {<br />    $(<span style="color: #006080">&quot;[data-query]&quot;</span>).removeClass(<span style="color: #006080">&quot;querySelected&quot;</span>);<br />    $(<span style="color: #0000ff">this</span>).addClass(<span style="color: #006080">&quot;querySelected&quot;</span>);<br />    <span style="color: #008000">// Do any work on the selected element</span><br />});<br /></pre>

  <br /></div>

<p>The first line removes the querySelected class from any elements that have the data-query attribute. This basically removes the highlighting from all elements in the list. The second line adds the querySelected class only to the element that received the click, basically highlighting that element.</p>

<p>In the rest of the click function, you can add other operations you might want to perform when you click on a list item.</p>]]></content:encoded>
    </item>
    <item>
      <title>How to Name Test Methods</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/how-to-name-test-methods</link>
      <pubDate>Sun, 11 Mar 2012 10:30:46 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2012/03/11/how-to-name-test-methods/</guid>
      <description><![CDATA[I really like BDD (Behavior Driven Development) and it’s structure for helping to focus on behavior...]]></description>
      <content:encoded><![CDATA[<p>I really like BDD (Behavior Driven Development) and it’s structure for helping to focus on behavior instead of implementation when you write unit tests. Some time ago I ran across a blog post by my former colleague in the patterns &amp; practices group Daniel Cazzulino: <a href="http://blogs.clariusconsulting.net/kzu/writing-meaningful-self-documenting-behavior-oriented-tests/">Writing meaningful, self-documenting, behavior-oriented tests</a>. Another good post, which has more links to BDD is this one: <a href="http://blogs.clariusconsulting.net/kzu/approaching-behavior-driven-development-bdd-from-a-test-driven-development-tdd-perspective/">Approaching Behavior Driven Development (BDD) from a Test Driven Development (TDD) perspective</a>.</p>  <p>As a result, I started naming my tests with names like this, using underscores to separate the different BDD keywords:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br />[Description(<span style="color: #006080">&quot;Column order is different, but tables match&quot;</span>)]<br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> ShouldNotThrow_WhenAreEqual_GivenSameData_ButColumnOrderDifferent()</pre>

  <br /></div>

<p>This worked reasonably well in Visual Studio 2010 tests results window because I could show the Description column. That way the test results included an easy to read description (the Description attribute), as well as the Given/When/Then behind the test (although I put the Then part first and called it Should):</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/41/35/metablogapi/0243.image_237559EE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0243.image_5F00_237559EE.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" 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/41/35/metablogapi/6318.image_thumb_2A286371.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6318.image_5F00_thumb_5F00_2A286371.png" width="740" height="48" /></a></p>

<p>Then along came Dev11 beta. They’ve completely changed the test results experience. The new version, at least in the beta, doesn’t support the description attribute, so you only see the test method names, resulting in my test results looking 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/41/35/metablogapi/1738.image_46900580.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1738.image_5F00_46900580.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" 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/41/35/metablogapi/8267.image_thumb_0A6439D8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/8267.image_5F00_thumb_5F00_0A6439D8.png" width="229" height="130" /></a></p>

<p>Argh! That makes it really hard to read test methods. Plus, I wasn’t completely happy with the long test methods anyway. What to do?</p>

<h2>Rethinking Test Method Naming</h2>

<p>I had a nice conversation with another former p&amp;p colleague, Peter Provost, who is a PM working on the test experience. He suggested that I put the BDD description into the Description attribute. I decided to try this out, and so far I’m liking the change:</p>

<div>
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">// Column order is different, but tables match</span><br />[TestMethod]<br />[Description(<span style="color: #006080">&quot;Given two tables And same data But different column order | When TableAssert | Then true&quot;</span>)]<br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> ColumnOrderDoesntMatter()</pre>
</div>

<div>&#160;</div>

<div>Here is what this looks like in the new test runner:</div>

<div>
  <br /></div>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/41/35/metablogapi/7288.image_4B62BD9E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/7288.image_5F00_4B62BD9E.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" 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/41/35/metablogapi/6683.image_thumb_7D5A5E28.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6683.image_5F00_thumb_5F00_7D5A5E28.png" width="233" height="30" /></a></p>



<p>One nice thing about this approach is that the BDD description is easier to read and it can be richer without overwhelming the method name.</p>

<h2>Wishful Thinking</h2>

<p>I think it would be really cool (just my opinion) if this had a rich tooltip that showed the class information (the current tooltop does) and also the Description attribute. It would also be really cool if I could write an VS extension that would format my descriptions into multiple lines with keywords like Given, When, and Then in bold. Hint, hint VS guys…</p>]]></content:encoded>
    </item>
    <item>
      <title>Retrieving TFS Results from a Tree Query</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/retrieving-tfs-results-from-a-tree-query</link>
      <pubDate>Wed, 22 Feb 2012 10:22:22 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2012/02/22/retrieving-tfs-results-from-a-tree-query/</guid>
      <description><![CDATA[I recently needed to retrieve the results from a TFS tree query using .NET code, via calls to the...]]></description>
      <content:encoded><![CDATA[<p>I recently needed to retrieve the results from a TFS tree query using .NET code, via calls to the TFS API. It was easy to find examples for retrieving a set of work items from a flat query, but I couldn’t find any information about how to retrieve a tree. I did find a few people talking about some ways to do it, but they said it was too slow.</p>  <p>In this blog post I’ll show you a very fast way to retrieve a tree of results. Let’s start with the query I’m using:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><p><span style="color: #0000ff">SELECT</span> [System.Id], <br />       [System.Title], <br />       [Microsoft.VSTS.Common.BacklogPriority], <br />       [System.AssignedTo], <br />       [System.State, <br />       [Microsoft.VSTS.Scheduling.RemainingWork], <br />       [Microsoft.VSTS.CMMI.Blocked], <br />       [System.WorkItemType] <br /><span style="color: #0000ff">  FROM</span> <font style="background-color: #ffff00">WorkItemLinks</font> <br /><span style="color: #0000ff"> WHERE</span> (<br />        Source.[System.TeamProject] = @project <br />    <span style="color: #0000ff">AND</span> Source.[System.WorkItemType] <span style="color: #0000ff">IN</span> (<span style="color: #006080">'Product Backlog Item'</span>, <span style="color: #006080">'Bug'</span>)<br />    <span style="color: #0000ff">AND</span> (<br />        Source.[System.State] &lt;&gt; <span style="color: #006080">'Removed'</span> <br />        <span style="color: #0000ff">AND</span> Source.[System.State] &lt;&gt; @closedState<br />&#160;&#160;&#160;&#160;&#160; )<br />&#160;&#160;&#160; )<br /><font style="background-color: #f4f4f4">    </font><span style="color: #0000ff">AND</span> [System.Links.LinkType] = <span style="color: #006080">'System.LinkTypes.Hierarchy-Forward'</span><br />    <span style="color: #0000ff">AND</span> Target.[System.WorkItemType] &lt;&gt; <span style="color: #006080">''</span><br /><span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> [Microsoft.VSTS.Common.StackRank], [Microsoft.VSTS.Common.Priority], [System.Id] mode(<span style="color: #0000ff">Recursive</span>)</p></pre>

  <br /></div>

<p>I’ve highlighted the FROM location, which in this case is WorkItemLinks, which you need to use in order to retrieve a hierarchy. Flat querys pull from WorkItems.</p>

<p>Retrieving a tree of work items actually takes two queries. The first query returns a list of work item IDs that contains SourceId and TargetId values (parent and child IDs when the link type is Hierarchy-Forward as here). However, the query does not return any of the details of the work item. For that you’ll need a second query (described later).</p>

<p>The tree query above also contains two parameters (@project and @closedState) that will need values. Here is a code snippet that shows supplying values and retrieving the list of IDs:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">Dictionary&lt;<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>&gt; parameters = <span style="color: #0000ff">new</span> Dictionary&lt;<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>&gt;();<br />parameters.Add(<span style="color: #006080">&quot;project&quot;</span>, _tfsProjectName);<br />parameters.Add(<span style="color: #006080">&quot;closedState&quot;</span>, <span style="color: #006080">&quot;Done&quot;</span>);<br /><br />var treeQuery = <span style="color: #0000ff">new</span> Query(_workItemStore, wiql, parameters);<br />WorkItemLinkInfo[] links = treeQuery.RunLinkQuery();</pre>

  <br /></div>

<p>The first part of the code creates a dictionary with the parameter values to use when running the query. You must use the RunLinkQuery method to run the query, instead of the RunQuery method, when working with WorkItemLinks. Calling RunQuery when you reference WorkItemLinks will throw an exception.</p>

<p>The links array returned from this query might look something like this:</p>

<table border="0" cellspacing="0" cellpadding="2" width="100"><tbody>
    <tr>
      <td valign="top" width="25"><strong>SourceId</strong></td>

      <td valign="top" width="25"><strong>TargetId</strong></td>

      <td valign="top" width="25"><strong>LinkTypeId</strong></td>

      <td valign="top" width="25"><strong>IsLocked</strong></td>
    </tr>

    <tr>
      <td>0</td>

      <td>23268</td>

      <td>0</td>

      <td>FALSE</td>
    </tr>

    <tr>
      <td>23268</td>

      <td>23339</td>

      <td>2</td>

      <td>FALSE</td>
    </tr>

    <tr>
      <td>23268</td>

      <td>23464</td>

      <td>2</td>

      <td>FALSE</td>
    </tr>

    <tr>
      <td>0</td>

      <td>23633</td>

      <td>0</td>

      <td>FALSE</td>
    </tr>

    <tr>
      <td>23633</td>

      <td>24664</td>

      <td>2</td>

      <td>FALSE</td>
    </tr>
  </tbody></table>

<p>These results represent a tree. In our case the tree has just one level of children. As an example, work item 23268 is the parent of two other work items: 23339 and 23464. However, more importantly, the results of running this query do not return any of the fields from the query. How do you get those fields? You have to run another query that returns the results. The second query needs to use the set of columns from the original query, but pull from the WorkItems “table” instead of WorkItemLinks.</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">//</span><br /><span style="color: #008000">// Build the list of work items for which we want to retrieve more information</span><br /><span style="color: #008000">//</span><br /><span style="color: #0000ff">int</span>[] ids = (from WorkItemLinkInfo info <span style="color: #0000ff">in</span> links<br />             select info.TargetId).ToArray();<br /><br /><span style="color: #008000">//</span><br /><span style="color: #008000">// Next we want to create a new query that will retrieve all the column values from the original query, for</span><br /><span style="color: #008000">// each of the work item IDs returned by the original query.</span><br /><span style="color: #008000">//</span><br />var detailsWiql = <span style="color: #0000ff">new</span> StringBuilder();<br />detailsWiql.AppendLine(<span style="color: #006080">&quot;SELECT&quot;</span>);<br /><span style="color: #0000ff">bool</span> first = <span style="color: #0000ff">true</span>;<br /><br /><span style="color: #0000ff">foreach</span> (FieldDefinition field <span style="color: #0000ff">in</span> treeQuery.DisplayFieldList)<br />{<br />    detailsWiql.Append(<span style="color: #006080">&quot;    &quot;</span>);<br />    <span style="color: #0000ff">if</span> (!first)<br />        detailsWiql.Append(<span style="color: #006080">&quot;,&quot;</span>);<br />    detailsWiql.AppendLine(<span style="color: #006080">&quot;[&quot;</span> + field.ReferenceName + <span style="color: #006080">&quot;]&quot;</span>);<br />    first = <span style="color: #0000ff">false</span>;<br />}<br />detailsWiql.AppendLine(<span style="color: #006080">&quot;FROM WorkItems&quot;</span>);<br /><br /><span style="color: #008000">//</span><br /><span style="color: #008000">// Get the work item details</span><br /><span style="color: #008000">//</span><br />var flatQuery = <span style="color: #0000ff">new</span> Query(_workItemStore, detailsWiql.ToString(), ids);<br />WorkItemCollection details = flatQuery.RunQuery();</pre>

  <br /></div>

<p>Here is what this code does:</p>

<ul>
  <li>Create an array of work item ids in the same order as returned by the tree query</li>

  <li>Build a new query that has this form: “SELECT {field list} FROM WorkItems”. The Query instance used to retrieve the tree of work item IDs has a property called DisplayFieldList that contains the the list of fields contained in the query. The code uses this list to build a new flat query that returns all the fields from the original tree query.</li>

  <li>Call the RunQuery method on the new flat query</li>
</ul>

<p>The set of work items returned by this new query will be in exactly the same order as the link query results at the top of this post. You can then “combine” these two results sets to build a tree and use this tree as you need.</p>

<p>Using this approach is very fast because there are just two queries. I don’t have any inside knowledge about how the TFS client using the SDK to retrieve results, but I wouldn’t be surprised if it’s very much like what I’ve outlined here.</p>]]></content:encoded>
    </item>
    <item>
      <title>Allowing Localizing after-the-fact using MUI</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/allowing-localizing-after-the-fact-using-mui</link>
      <pubDate>Wed, 14 Dec 2011 14:46:39 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2011/12/14/allowing-localizing-after-the-fact-using-mui/</guid>
      <description><![CDATA[Here is the problem. We built an English-only C++ application. However, now some of our customers...]]></description>
      <content:encoded><![CDATA[<p>Here is the problem. We built an English-only C++ application. However, now some of our customers are asking how they can translate the application into other languages. We don’t have the budget to provide translated versions ourselves, and they’d be happy to do the work themselves. Is there a way they can translate our application after the fact? And without our involvement?</p>  <p>I thought the answer was “no,” until someone suggested MUI. My first reaction was “what’s that?” MUI, as it turns out, stands for <a href="http://msdn.microsoft.com/en-us/library/dd319073(v=VS.85).aspx">Multilingual User Interface</a> and has been supported in one way or another since Windows XP. I did not know this. The idea is that you remove the resources from your main binaries and instead put them into MUI files, which are just DLLs with a different extension. For example:</p>  <blockquote>   <p>MyApplication.exe&#160; &lt;— No resources      <br />en-US       <br />&#160;&#160;&#160; MyApplication.exe.mui&#160; &lt;— Language-neutral (in this case English)      <br />de       <br />&#160;&#160;&#160; MyApplication.exe.mui&#160; &lt;— German      <br />&#160;&#160;&#160; </p> </blockquote>  <p>In the picture above, the first MUI file (under the en-US directory) contains the English resources (strings, dialog boxes, etc.). This MUI file is marked as both the en-US file and the language-neutral file that will be used when Windows can’t find a better match.</p>  <p>The second MUI (under the de directory) contains the German resources that will be used whenever the Windows’ current language is German (weather that be in Germany, or any other country).</p>  <p>With very little work (less than a day), we were able to build a version of our application that our customers can translate to their heart’s content. Below I describe the steps for a developer to make their application translatable after the fact.</p>  <h1>Before you Start</h1>  <p>In order to create an MUI-aware application, you’ll need to install the Windows 7 SDK, which is where you’ll find <a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx">MUIRCT</a>.</p>  <h2>Creating the MUI Files</h2>  <p>You may not need to make many changes in your application to make all of this work if you only support Vista or later. If you require Windows XP support, you’ll need to read the section below.</p>  <p>The first step is to run a program called <a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx">MUIRCT</a> that will move the resources from your main executables into satellite executables. This program requires a config file that describes which resources to move over. Here is the file I used:</p>  <div>   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span>?<span style="color: #0000ff">&gt;</span> <br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">localization</span><span style="color: #0000ff">&gt;</span><br />  <span style="color: #0000ff">&lt;</span><span style="color: #800000">resources</span><span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">win32Resources</span> <span style="color: #ff0000">fileType</span><span style="color: #0000ff">=&quot;Application&quot;</span><span style="color: #0000ff">&gt;</span><br />      <span style="color: #0000ff">&lt;</span><span style="color: #800000">neutralResources</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#16&quot;</span> <span style="color: #0000ff">/&gt;</span><br />      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">neutralResources</span><span style="color: #0000ff">&gt;</span><br />      <span style="color: #0000ff">&lt;</span><span style="color: #800000">localizedResources</span><span style="color: #0000ff">&gt;</span> <br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#2&quot;</span> <span style="color: #0000ff">/&gt;</span><br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#3&quot;</span> <span style="color: #0000ff">/&gt;</span><br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#4&quot;</span> <span style="color: #0000ff">/&gt;</span><br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#5&quot;</span> <span style="color: #0000ff">/&gt;</span><br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#6&quot;</span> <span style="color: #0000ff">/&gt;</span><br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#9&quot;</span> <span style="color: #0000ff">/&gt;</span><br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#11&quot;</span> <span style="color: #0000ff">/&gt;</span><br />         <span style="color: #0000ff">&lt;</span><span style="color: #800000">resourceType</span> <span style="color: #ff0000">typeNameId</span><span style="color: #0000ff">=&quot;#16&quot;</span> <span style="color: #0000ff">/&gt;</span><br />      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">localizedResources</span><span style="color: #0000ff">&gt;</span> <br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">win32Resources</span><span style="color: #0000ff">&gt;</span><br />  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">resources</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">localization</span><span style="color: #0000ff">&gt;</span><br /></pre>
</div>

<p>For more details, read <a href="http://msdn.microsoft.com/en-us/library/dd319100(v=VS.85).aspx">Preparing a Resource Configuration File</a> on MSDN.</p>

<p>Next you’ll need to run <a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx">MUIRCT</a> to split your files:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">muirct.exe -q muiconfig.xml -v 1 -x 0x0409  ..\MyApplication.exe MyApplication.exe en-US\MyApplication.exe.mui</pre>
</div>

<p>The “..\MyApplication” refers to the original EXE that contains all the language-neutral resources (the 0x409 says they’re en-US resources). The second-to-last parameter, “MyApplication.exe” is the name that will be used for the new version that contains none of the resources being moved. Finally, the last parameter contains the name of the MUI file that will be created to contain all the resources that are called out in the config file as resource you want to move.</p>

<p>If you have no need to support Windows XP, you’re done.</p>

<h2>Supporting Windows XP</h2>

<p>Windows Vista and later automatically handle locating and using the correct MUI file for resources. However, if your application needs to be able to run on Windows XP as well, you’ll need to make some changes to your code. In our case that was really easy because the calls to load strings were all encapsulated in a helper class. The idea is that you’ll need to call a new API that will located and load the best-match MUI file:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">std::vector&lt;WCHAR&gt; moduleName(MAX_PATH);<br /><br />GetModuleFileName(hModule, &amp;moduleName[0], moduleName.size());<br />hInstance = ::LoadMUILibrary(moduleName.data(), MUI_LANGUAGE_NAME, 0);<br /></pre>

  <br /></div>

<p align="left">The first two lines get the name of the executable that we’re running. The last line is where the magic happens. <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd318709(v=vs.85).aspx">LoadMUILibrary</a> is a function that in Windows XP will locate the appropriate satellite MUI file, load that file, and return an instance handle to that file. In Windows Vista and later, this call returns the instance handle for your main executable because the system automatically handles resource location in calls like LoadString.</p>

<p align="left">Additionally, you’ll need to ensure you link to muiload.lib. I like to use a pragma in my source files, rather than setup additional libraries in the link options, using a line like this:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #cc6633">#pragma</span> comment(lib, <span style="color: #006080">&quot;muiload.lib&quot;</span>)</pre>

  <br /></div>

<h2></h2>

<h2>Localizing MUI Files</h2>

<p>I’m not an expert on localization, so I’m not sure what most companies use to localize native Windows applications. Here at Microsoft we use a tool called LocStudio, and I understand there are similar programs available outside of Microsoft.</p>

<p>Whichever tool you use, here’s what you have to do:</p>

<ul>
  <li>Create a new directory for the new locale using the two-letter language identifier (like “de” for German)</li>

  <li>Copy the language-neutral MUI file</li>

  <li>Translate the strings (and possibly change control sizes and positions in dialogs)</li>

  <li>Copy the localized MUI file into the new directory (“de” in this example)</li>
</ul>

<p>Just a quick note about Visual Studio. You can open native Windows executable files and edit the resources in them with Visual Studio. However, you cannot save changes you make to MUI files, so you’ll have to use another tool. Again, I don’t have knowledge of those other tools.</p>

<h2>Working with Signed Binaries</h2>

<p>What happens if the original binaries and MUI files are code signed? It just works. I didn’t know the answer to this so I tested it. I used <a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx">MUIRCT</a> to split the files, and then code-signed both the main executable and the MUI file. Then I made a localized copy of the MUI file for German that was not signed. I was able to run this and see the English strings when I ran with English as the default language for Windows. When I switched to German and ran the program again, it showed the German strings from the un-signed German MUI files.</p>]]></content:encoded>
    </item>
    <item>
      <title>Capturing Code Coverage for Coded UI Tests</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/capturing-code-coverage-for-coded-ui-tests</link>
      <pubDate>Fri, 02 Dec 2011 10:45:27 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2011/12/02/capturing-code-coverage-for-coded-ui-tests/</guid>
      <description><![CDATA[You would think that simply running coded UI tests with everything setup for capturing code coverage...]]></description>
      <content:encoded><![CDATA[<p>You would think that simply running coded UI tests with everything setup for capturing code coverage would just work, right? And if you’re running your coded UI tests on a 32-bit operating system, it will.</p>  <p>However, if you’re running your tests on a 64-bit operating system, chances are you’ll see the test results (pass/fail), but you won’t see any code coverage results. Why not? And how do you fix it?</p>  <p>By default, the test runner in Visual Studio (and on the TFS build server) run as a 32-bit process, which also means that the code coverage tools are the 32-bit versions. When you run unit tests, the test runner loads all the assemblies into the test runner’s process, which means that .NET assemblies will be run as 32-bit assemblies.</p>  <p>The problem occurs when you used coded UI tests. In this case, the executable assembly is <strong>not</strong> loaded into the test runners process. Instead, it’s launched in a new process. If you assembly is marked as Any CPU, and you running on a 64-bit OS, the application you’re testing will now be a 64-bit application, which means the 32-bit code coverage code won’t be able to capture any code coverage for your code UI tests.</p>  <p>How do you fix this? Basically you want to make sure the builds used for test runs have the EXE targeted for 32-bit rather than Any CPU. One way is to modify the solution so it builds targets the main EXE to 32-bit, as shown here (this is the Configuration Manager dialog for the solution):</p>  <p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" 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/41/35/metablogapi/8267.image_49CFE931.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/8267.image_5F00_49CFE931.png" width="392" height="208" /></p>  <p>The other option is to change the target platform in the build definition</p>  <p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" 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/41/35/metablogapi/2620.image_7B5B56C6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/2620.image_5F00_7B5B56C6.png" width="402" height="77" /></p>    <p>Using either approach will force the assembly that you want to test to be built for the 32-bit platform.</p>]]></content:encoded>
    </item>
    <item>
      <title>Shrinking the Arrow on the WPF Expander</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/shrinking-the-arrow-on-the-wpf-expander</link>
      <pubDate>Wed, 05 Oct 2011 18:57:57 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2011/10/05/shrinking-the-arrow-on-the-wpf-expander/</guid>
      <description><![CDATA[My goal was simple. I needed a smaller arrow in the WPF Expander control to help conserve screen...]]></description>
      <content:encoded><![CDATA[<p>My goal was simple. I needed a smaller arrow in the WPF Expander control to help conserve screen real-estate. Here is the before and after:</p>  <table border="0" cellspacing="0" cellpadding="2" width="100"><tbody>     <tr>       <td valign="top" width="50">Before:</td>        <td valign="top" width="50"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" 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/41/35/metablogapi/6813.image_7F0F13FE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6813.image_5F00_7F0F13FE.png" width="23" height="22" /></td>     </tr>      <tr>       <td valign="top" width="50">After:</td>        <td valign="top" width="50"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" 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/41/35/metablogapi/4353.image_4A0284CE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/4353.image_5F00_4A0284CE.png" width="18" height="17" /></td>     </tr>   </tbody></table>  <p>The arrow on the right is 80% of the original size.</p>  <p>So how did I accomplish this? It turned out to be far simpler than any of the blog posts I found on the subject. They all suggested using Expression Blend to copy the full template and them modify it. But you can use a RenderTransform to reduce the size:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">Expander</span> <span style="color: #ff0000">Header</span><span style="color: #0000ff">=&quot;{Binding Name}&quot;</span> <span style="color: #ff0000">FontSize</span><span style="color: #0000ff">=&quot;16&quot;</span><span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Expander.RenderTransform</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">ScaleTransform</span> <span style="color: #ff0000">ScaleX</span><span style="color: #0000ff">=&quot;.8&quot;</span> <span style="color: #ff0000">ScaleY</span><span style="color: #0000ff">=&quot;.8&quot;</span> <span style="color: #0000ff">/&gt;</span><br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Expander.RenderTransform</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Expander</span><span style="color: #0000ff">&gt;</span></pre>

  <br /></div>

<p>Notice that I bumped the font size up to 16. When multiplied by .8, this gives a final font size of 12.8, which is a nice size.</p>]]></content:encoded>
    </item>
    <item>
      <title>Delay Signing a C++/CLI Assembly</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/delay-signing-a-ccli-assembly</link>
      <pubDate>Fri, 09 Sep 2011 17:40:51 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2011/09/09/delay-signing-a-ccli-assembly/</guid>
      <description><![CDATA[This should be easy, right? Just set the link options to delay sign the assembly with an SNK file....]]></description>
      <content:encoded><![CDATA[<p>This should be easy, right? Just set the link options to delay sign the assembly with an SNK file. There were two issues I ran into, which I’ll describe here.</p>  <h2>Fixing Delay Signing in SP1</h2>  <p>I used the /DELAYSIGN and /KEYFILE settings in the properties page for my C++/CLI project and everything compiled just fine. However, when I tried to use an object from this DLL, I got this message::</p>  <blockquote>   <p>CS1577: Assembly generation failed … <strong>does not have a strong name</strong></p> </blockquote>  <p>This certainly wasn’t what I expected. My first step was to double-check the signing on the assembly. I used the following command-line command to check:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">sn -T <em>AssemblyName</em>.dll</pre>

  <br /></div>

<p>When I ran this command, it reported “AssemblyName.dll <strong>does not represent a strongly named assembly</strong>&quot;. Obviously the properties I set in the project settings dialog weren’t working. After quite a bit of searching, I found a blog post by <a href="http://blogs.msdn.com/b/vcblog/archive/2011/03/11/10140139.aspx">Amit Mohindra</a> that explained the problem, which is a change in Visual Studio 2010 SP1.</p>

<p>The blog post had suggestions on how to fix the problem, but it seemed like quite a bit of work. I tried another approach, which worked just fine.</p>

<h2>Signing via AssemblyInfo.cpp</h2>

<p>I added an new file called AssemblyInfo.cpp to my project, which has the following contents:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><p><span style="color: #cc6633">#include</span> <span style="color: #006080">&quot;stdafx.h&quot;<br /> </span><br /><br /><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> System;<br /><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> System::Reflection;<br /> <br /><br />[assembly:AssemblyKeyFile(<span style="color: #006080">&quot;myKey.snk&quot;</span>)];<br />[assembly:AssemblyDelaySign(true)];</p></pre>

  <br /></div>

<p>This took care of signing the assembly, which I verified using the sn command.</p>

<h2>Dealing with C++/CLI vs C# Assemblies</h2>

<p>One this was all working, we added a call from our C# EXE into the C++/CLI assembly, and got this run-time error:</p>

<blockquote>
  <p>Could not load file or assembly 'AssemblyName, Version=0.0.0.0, Culture=neutral, PublicKeyToken=…' or one of its dependencies. An attempt was made to load a program with an <strong>incorrect format</strong>.</p>
</blockquote>

<p>Incorrect format? Huh?</p>

<p>With a little more searching, I found the problem, and now that I understand the problem, it makes perfect sense. First, the solution. You need to change the <strong>Platform</strong> from <strong>Any CPU</strong> to <strong>x86</strong> for you main EXE (or x64 if you’re building a 64-bit version) to match the bitness of your C++/CLI assembly:</p>

<blockquote>
  <p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" 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/41/35/metablogapi/8524.image_18E08B20.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/8524.image_5F00_18E08B20.png" width="481" height="68" /></p>
</blockquote>

<p>Here’s why we had to make this change. Our C++/CLI assembly is calling not a pure .NET assembly since it’s making calls to windows APIs. As such, the C++/CLI assembly needs to be either 32- or 64-bit. It can’t be both because of the native C++ code it contains. A .NET assembly that is built for Any CPU can run as either a 32- or 64-bit process, but you can’t load a 32-bit DLL into a 64-bit process, hence the error. Building a 32-bit .NET EXE that loads the 32-bit C++/CLI DLL fixes the problem.</p>]]></content:encoded>
    </item>
    <item>
      <title>Interpreting C++ Code Coverage Results</title>
      <link>https://docs.microsoft.com/archive/blogs/jsocha/interpreting-c-code-coverage-results</link>
      <pubDate>Wed, 17 Aug 2011 12:48:58 GMT</pubDate>
      <dc:creator><![CDATA[John Socha-Leialoha - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jsocha/2011/08/17/interpreting-c-code-coverage-results/</guid>
      <description><![CDATA[You’ve finally gotten code coverage results for your C++ code. But now your code coverage numbers...]]></description>
      <content:encoded><![CDATA[<p>You’ve finally gotten code coverage results for your C++ code. But now your code coverage numbers are lower than you expected. Why is that? And how do you get around it?</p>  <p>There are several issues that make C++ code coverage data “noisy” and/or inaccurate. First, if you use the standard C++ libraries, you’ll find the code coverage results littered with entries from the std namespace, which represents classes and methods provided by Microsoft. Clearly, you don’t want library classes provided by Microsoft to impact your code coverage results. Especially if it lowers your numbers.</p>  <p>Another issue has to do with using template classes. Look at this example, which is a real example from some of our code:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/41/35/metablogapi/4722.clip_image002_15F51109.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/4722.clip_5F00_image002_5F00_15F51109.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" 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/41/35/metablogapi/0525.clip_image002_thumb_3C56F454.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0525.clip_5F00_image002_5F00_thumb_5F00_3C56F454.jpg" width="485" height="147" /></a></p>  <p>You would probably expect this to show 100% code coverage in Visual Studio (or TFS). It doesn’t. In fact, it reports 72% code coverage. The problem is the return statement at the end. Visual Studio reports code coverage in terms of <a href="http://msdn.microsoft.com/en-us/library/cc667391.aspx">blocks covered/not covered</a> (also <a href="http://msdn.microsoft.com/en-us/library/dd299398.aspx">this article</a>). There are blocks in the wstring class that aren’t being covered in this method.</p>  <p>How do you fix this problem?</p>  <h1>Building a Code Coverage Report</h1>  <p>There are probably many ways to provide better code coverage numbers for C++ code. I chose to write a report for TFS that reads results from the data warehouse and process them to produce more “useful” results. Here is an overview of what the report does with the data (I’ll describe each in more detail):</p>  <ul>   <li>Use lines instead of blocks for coverage information </li>    <li>Treat partially covered lines as covered </li>    <li>Collapse concrete template instances into a “common” instance </li>    <li>Use the method results with the highest coverage </li>    <li>Filter out namespaces and functions </li> </ul>  <p>The following sections describe each of these bullets in more detail.</p>  <h3>Use lines instead of blocks, and treat partially covered as covered</h3>  <p>I debated a long time before making these changes. Visual Studio reports code coverage results based on block coverage, so I wasn’t sure how people would react to using lines instead. However, switching to lines and also treating partially covered lines as covered mitigates the issue I described above. It does mean we’re over-reporting coverage for lines that have conditional code, but our style guidelines call for using multiple lines in such cases, so this is probably a small issue.</p>  <p>Alternatively, there are Visual Studio APIs, found in the <a href="http://msdn.microsoft.com/en-us/library/dd347161.aspx">Microsoft.VisualStudio.Coverage.Analysis</a> namespace that could be used to process the code coverage results. I haven’t tried this, and it would have taken more time than writing a report.</p>  <h3>Collapse template instances</h3>  <p>We have some template classes that we use as base classes. The methods are well covered with unit tests. However not all concrete instances call the base methods, and we have a number of concrete instances of these classes. The result is that we get partial code coverage multiplied by the number of concrete instances. Our desire is to know how much coverage we achieve for the code we wrote, not for compiler-generated code. As such, I chose to collapse concrete instances. For example, we have a template called BaseControl, with a concrete instance called BaseControl&lt;ItreeView&gt;. In the report, I collapse this into BaseControl__ so that we can “combine” the results for each base method from sub classes. This brings us to the next topic.</p>  <h3>Use the highest coverage results</h3>  <p>We have several different runs on our build server, and we want to combine these in the report results. For example, we have unit tests run during gated check-ins, and we runs all our automated acceptance tests nightly. The acceptance tests cover some code (such as UI code) that isn’t covered by the unit tests, and visa versa.</p>  <p>Because of the testing approach we’re using, the unit tests are written in C++/CLI and include the product code directly into the test DLL (see <a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx">Writing Unit Tests in Visual Studio for Native C++</a>) whereas our acceptance tests are written in C# and use the production DLL. This results in the DLL names being different between these two runs. The report I created replaces these different names with a common name so the data can be combine.</p>  <p>One the report collapses template instances and combined results from DLLs with different names, but representing the same code, there may be more than one record (result) for each method in the product code. How do you combine these records? TFS stores the name of the class and method, as well as lines covered, not covered, and partially covered (and also block information). I chose to use the record for each method that has the highest coverage. So if you have different test runs that cover different parts of a method, choosing the result with the highest coverage will under-report code coverage since there’s no way to tell how much overlap there is between different result records.</p>  <h1>Filter out namespaces and functions</h1>  <p>In my MSDN article, <a href="http://msdn.microsoft.com/en-us/magazine/hh205645.aspx">Agile C++ Development and Testing with Visual Studio and TFS</a>, I talked about filtering out common patterns, such as “std::”, from the results because this represents library code that we don’t want to include. Since then, I’ve found even more patterns, so the new report I created excludes a much larger list.</p>  <h1>Using the Results</h1>  <p>The results of all this work were very significant. Switching from block to line coverage moved our code coverage results up from 62% for one DLL to about 70%. Doing all the other work took this number up to 87%, which is more of what I expected to see since we used TDD to write all the code in that DLL.</p>  <h1>Using the Report</h1>  <p>If you’ve never added a new report to your reporting site, you can find some instructions here: <a title="http://blogs.msdn.com/b/aaronbjork/archive/2010/07/30/microsoft-visual-studio-scrum-1-0-updated-sprint-burndown-report.aspx" href="http://blogs.msdn.com/b/aaronbjork/archive/2010/07/30/microsoft-visual-studio-scrum-1-0-updated-sprint-burndown-report.aspx">http://blogs.msdn.com/b/aaronbjork/archive/2010/07/30/microsoft-visual-studio-scrum-1-0-updated-sprint-burndown-report.aspx</a>.</p>  <p><img alt="Source Code" align="middle" src="http://archive.msdn.microsoft.com/Images/SourceCode.gif" /> <a href="http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mpsddev&amp;DownloadId=15624">Code Coverage.rdl</a></p>  <p>Once you install the report in your team project, you’ll see something that looks 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/41/35/metablogapi/2766.image_7C20DAD9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/2766.image_5F00_7C20DAD9.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" 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/41/35/metablogapi/0284.image_thumb_54E691A4.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0284.image_5F00_thumb_5F00_54E691A4.png" width="629" height="330" /></a></p>  <h2>Customizing the Report</h2>  <p>There are several places where you can customize the report. Open the report in Report Manager (right click on the <strong>Reports</strong> node in <strong>Team Explorer</strong> inside Visual Studio and select <strong>Show Report Site</strong>), click the <strong>Properties</strong> tab, then click <strong>Parameters</strong>. You’ll 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/41/35/metablogapi/1373.image_429DCAE2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1373.image_5F00_429DCAE2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" 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/41/35/metablogapi/1185.image_thumb_345F51F2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1185.image_5F00_thumb_5F00_345F51F2.png" width="635" height="311" /></a></p>  <p>There are several hidden parameters you can use to provide more control over what you see in the report:</p>  <table border="0" cellspacing="0" cellpadding="2" width="622"><tbody>     <tr>       <td valign="top" width="133">MinStartOffset</td>        <td valign="top" width="487">The default is -5, which means the report will only show builds within the last 5 days.</td>     </tr>      <tr>       <td valign="top" width="133">IgnoreBuilds</td>        <td valign="top" width="487">A set of build definitions that you don’t want to show up in the Build Definitions parameter. I’ve used the name “empty” when there are no builds I want to ignore.</td>     </tr>      <tr>       <td valign="top" width="133">IgnoreAssemblies</td>        <td valign="top" width="487">A list of assemblies that you want to exclude from the report. This is useful to us because we have several projects that share source, so they’re all part of the same gated build definition.</td>     </tr>      <tr>       <td valign="top" width="133">DefaultBuildDefinitions</td>        <td valign="top" width="487">The list of build definitions that you want to be selected when you first run a report.</td>     </tr>   </tbody></table>  <p>Remember to click <strong>Apply</strong> to save changes you make to these parameters.</p>]]></content:encoded>
    </item>
  </channel>
</rss>