<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Francis K. Cheung</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/francischeung/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/francischeung/feed.xml</link>
    <description>The journey of an agile programmer...</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:05:54 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Prism 5.0 for WPF just shipped.</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/prism-5-0-for-wpf-just-shipped</link>
      <pubDate>Mon, 21 Apr 2014 14:23:07 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2014/04/21/prism-5-0-for-wpf-just-shipped/</guid>
      <description><![CDATA[Prism version 5.0 for WPF is now available. This version of Prism includes updates to existing and...]]></description>
      <content:encoded><![CDATA[<p>Prism version 5.0 for WPF is now <a href="https://msdn.microsoft.com/en-us/library/gg406140.aspx" target="_blank">available</a>. This version of Prism includes updates to existing and several new NuGet packages:</p>  <ol>   <li><a href="https://www.nuget.org/packages/Prism/" target="_blank">Prism</a></li>    <li><a href="https://www.nuget.org/packages/Prism.Composition/" target="_blank">Prism.Composition</a> (New)</li>    <li><a href="https://www.nuget.org/packages/Prism.Interactivity/" target="_blank">Prism.Interactivity</a> (New)</li>    <li><a href="https://www.nuget.org/packages/Prism.Mvvm/" target="_blank">Prism.Mvvm</a> (New)</li>    <li><a href="https://www.nuget.org/packages/Prism.MEFExtensions/" target="_blank">Prism.MefExtensions</a></li>    <li><a href="https://www.nuget.org/packages/Prism.UnityExtensions/" target="_blank">Prism.UnityExtensions</a></li> </ol>  <p>We’ve updated Prism 4.1 with bug fixes and a few <a href="https://msdn.microsoft.com/en-us/library/gg430871(v=pandp.40).aspx" target="_blank">new features</a>. We’ve removed Silverlight support. Windows Phone 8.1 will be supported in a future project. I hope you find this guidance and accompanying libraries helpful and useful.</p>]]></content:encoded>
    </item>
    <item>
      <title>Maintaining proportional scroll position</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/maintaining-proportional-scroll-position</link>
      <pubDate>Mon, 23 Dec 2013 18:31:48 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2013/12/23/maintaining-proportional-scroll-position/</guid>
      <description><![CDATA[In the AdventureWorks Shopper app, we spent a lot of time making sure all GridView/ListView scroll...]]></description>
      <content:encoded><![CDATA[<p>In the AdventureWorks Shopper app, we spent a lot of time making sure all GridView/ListView scroll viewers’ scroll positions behave as intuitively as possible. This means that if you have a GridView/ListView that has enough content to pan, and you pan through, for example 75% of the content, you should be able to rotate the device, go to split screen, or even go to minimal width and the scroll bar should be vertical but still be at 75%. This also means that if you navigate forward and then back, the scroll bar should also show 75%.</p>  <p>Implementing this functionality was made much simpler in the AdventureWorks Shopper app with the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/12/23/the-autorotatinggridview-provides-gridview-landscape-and-listview-portrait-functionality-in-one-control.aspx" target="_blank">AutoRotatingGridView</a> control that automatically uses a horizontal scroll bar in landscape mode and a vertical scroll bar in portrait mode. </p>  <p>Let’s take a look at the AdventureWorks Shopper HubPage. To capture the AutoRotatingGridView’s scroll viewer’s scroll position we listen to the LayoutUpdated event.</p>  <ol>   <pre class="csharpcode"><span class="kwrd">void</span> itemGridView_LayoutUpdated(<span class="kwrd">object</span> sender, <span class="kwrd">object</span> e)
{
    _scrollViewerOffsetProportion = <br />         ScrollViewerUtilities.GetScrollViewerOffsetProportion(_itemsGridViewScrollViewer);
}</pre>
</ol>

<p>Notice that the LayoutUpdated event handler uses the itemGridView’s embedded ScrollViewer which is captured after the itemGridView is loaded.</p>

<ol>
  <pre class="csharpcode"><span class="kwrd">void</span> itemGridView_Loaded(<span class="kwrd">object</span> sender, RoutedEventArgs e)
{
    _itemsGridViewScrollViewer = VisualTreeUtilities.GetVisualChild&lt;ScrollViewer&gt;(itemGridView);
}</pre>
</ol>

<p>Here is the source for the GetVisualChild&lt;T&gt; method:</p>

<ol>
  <pre class="csharpcode"><span class="kwrd">public </span><span class="kwrd">static</span> T GetVisualChild&lt;T&gt;(DependencyObject parent) <span class="kwrd">where</span> T : DependencyObject
{
    T child = <span class="kwrd">default</span>(T);
    <span class="kwrd">int</span> numVisuals = VisualTreeHelper.GetChildrenCount(parent);
    <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; numVisuals; i++)
    {
        DependencyObject v = VisualTreeHelper.GetChild(parent, i);
        child = v <span class="kwrd">as</span> T;
        <span class="kwrd">if</span> (child == <span class="kwrd">null</span>)
            child = GetVisualChild&lt;T&gt;(v);
        <span class="kwrd">if</span> (child != <span class="kwrd">null</span>)
            <span class="kwrd">break</span>;
    }
    <span class="kwrd">return</span> child;
}
  </pre>
</ol>

<p>Here is the source for the GetScrollViewerOffsetProportion method:</p>

<ol>
  <pre class="csharpcode"><span class="kwrd">public </span><span class="kwrd">static</span> <span class="kwrd">double</span> GetScrollViewerOffsetProportion(ScrollViewer scrollViewer)
{
    <span class="kwrd">if</span> (scrollViewer == <span class="kwrd">null</span>) <span class="kwrd">return</span> 0;

    var horizontalOffsetProportion = (scrollViewer.ScrollableWidth == 0) ? 0 <br />              : (scrollViewer.HorizontalOffset / scrollViewer.ScrollableWidth);
    var verticalOffsetProportion = (scrollViewer.ScrollableHeight == 0) ? 0 <br />              : (scrollViewer.VerticalOffset / scrollViewer.ScrollableHeight);

    var scrollViewerOffsetProportion = Math.Max(horizontalOffsetProportion, verticalOffsetProportion);
    <span class="kwrd">return</span> scrollViewerOffsetProportion;
}</pre>
  </ol>

<p>Now that we’ve captured the scroll offset proportion (_scrollViewerOffsetProportion) after the user has scrolled, let’s use this value to scroll to the same approximate position when the user changes rotates their device or resizes the frame. When the page size changes we will check to see if the scroll viewer has finished resizing. We need to let the scroll viewer settle before we can change its scroll offset. One way we found to determine when the scroll viewer has stabilized is to examine the ComputedHorizontalScrollBarVisibility and ComputedVerticalScrollBarVisibility properties. </p>

<ul>
  <pre class="csharpcode"><span class="kwrd">void</span> Page_SizeChanged(<span class="kwrd">object</span> sender, SizeChangedEventArgs e)
{
    var scrollViewer = VisualTreeUtilities.GetVisualChild&lt;ScrollViewer&gt;(itemsGridView);

    <span class="kwrd">if</span> (scrollViewer != <span class="kwrd">null</span>)
    {
        <span class="kwrd">if</span> (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible <br />             &amp;&amp; scrollViewer.ComputedVerticalScrollBarVisibility == Visibility.Visible)
        {
            ScrollViewerUtilities.ScrollToProportion(scrollViewer, _scrollViewerOffsetProportion);
        }
        <span class="kwrd">else</span>
        {
            DependencyPropertyChangedHelper horizontalHelper = <br />                <span class="kwrd">new</span> DependencyPropertyChangedHelper(scrollViewer, <span class="str">&quot;ComputedHorizontalScrollBarVisibility&quot;</span>);
            horizontalHelper.PropertyChanged += ScrollBarVisibilityChanged;

            DependencyPropertyChangedHelper verticalHelper = <br />                <span class="kwrd">new</span> DependencyPropertyChangedHelper(scrollViewer, <span class="str">&quot;ComputedVerticalScrollBarVisibility&quot;</span>);
            verticalHelper.PropertyChanged += ScrollBarVisibilityChanged;
        }
    }
}</pre>
  </ul>

<p>If these two properties equal Visibility.Visible then the scroll viewer is ready to be modified/scrolled. If not, then we use the DependencyPropertyChangedHelper to listen for changes in these two dependency properties.</p>

<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> ScrollBarVisibilityChanged(<span class="kwrd">object</span> sender, DependencyPropertyChangedEventArgs e)
{
    var helper = (DependencyPropertyChangedHelper)sender;

    var scrollViewer = VisualTreeUtilities.GetVisualChild&lt;ScrollViewer&gt;(itemsGridView);

    <span class="kwrd">if</span> (((Visibility)e.NewValue) == Visibility.Visible)
    {
        ScrollViewerUtilities.ScrollToProportion(scrollViewer, _scrollViewerOffsetProportion);
        helper.PropertyChanged -= ScrollBarVisibilityChanged;
    };

    <span class="kwrd">if</span> (_isPageLoading)
    {
        itemsGridView.LayoutUpdated += itemsGridView_LayoutUpdated;
        _isPageLoading = <span class="kwrd">false</span>;
    }
}</pre>


<p>In the ScrollBarVisibilityChanged handler, we check to see if the dependency property has changed to Visible. If so, we update the scroll viewer by calling its ChangeView method.</p>

<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> ScrollToProportion(ScrollViewer scrollViewer, <span class="kwrd">double</span> scrollViewerOffsetProportion)
{
    <span class="rem">// Update the Horizontal and Vertical offset</span>
    <span class="kwrd">if</span> (scrollViewer == <span class="kwrd">null</span>) <span class="kwrd">return</span>;
    var scrollViewerHorizontalOffset = scrollViewerOffsetProportion * scrollViewer.ScrollableWidth;
    var scrollViewerVerticalOffset = scrollViewerOffsetProportion * scrollViewer.ScrollableHeight;

    scrollViewer.ChangeView(scrollViewerHorizontalOffset, scrollViewerVerticalOffset, <span class="kwrd">null</span>);
}</pre>

<p>To recap, we have:</p>

<ol>
  <li>Captured the AutoRotatingGridView’s scroll viewer’s offset value as a proportion to its total size.</li>

  <li>After the user resizes the window either by rotating the device or changing the size of the frame, we apply the offset proportion value back to the AutoRotatingGridView.</li>
</ol>

<p>Notice that if the user navigates to another page or the app is terminated, this offset proportion value is lost. In order to preserve this value, we utilize the SaveState and LoadState methods provided by the VisualStateAwarePage base class.</p>

<pre class="csharpcode">        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> SaveState(System.Collections.Generic.Dictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">object</span>&gt; pageState)
        {
            <span class="kwrd">if</span> (pageState == <span class="kwrd">null</span>) <span class="kwrd">return</span>;

            <span class="kwrd">base</span>.SaveState(pageState);

            pageState[<span class="str">&quot;scrollViewerOffsetProportion&quot;</span>] = <br />                ScrollViewerUtilities.GetScrollViewerOffsetProportion(_itemsGridViewScrollViewer);
        }
</pre>

<pre class="csharpcode">
        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> LoadState(<span class="kwrd">object</span> navigationParameter, Dictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">object</span>&gt; pageState)
        {
            <span class="kwrd">if</span> (pageState == <span class="kwrd">null</span>) <span class="kwrd">return</span>;

            <span class="kwrd">base</span>.LoadState(navigationParameter, pageState);

            <span class="kwrd">if</span> (pageState.ContainsKey(<span class="str">&quot;scrollViewerOffsetProportion&quot;</span>))
            {
                _scrollViewerOffsetProportion = <br />                    <span class="kwrd">double</span>.Parse(pageState[<span class="str">&quot;scrollViewerOffsetProportion&quot;</span>].ToString());                
            }
        }</pre>


<p>After the LoadState method populates the _scrollViewerOffsetProportion value, the Page_SizeChanged event handler mentioned above will update the scroll viewer to the appropriate scroll offset position.</p>

<p>I’ve tried to do this using separate GridView and ListView controls instead of a single AutoRotatingGridView control and the code is much more complicated and repetitive. You need to get the offset proportion from the GridView control and set it into the ListView control when the app goes from Landscape to Portrait, and vice versa when the app goes from Portrait to Landscape.</p>]]></content:encoded>
    </item>
    <item>
      <title>The AutoRotatingGridView: Provides GridView (Landscape) and ListView (Portrait) functionality in one control.</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/the-autorotatinggridview-provides-gridview-landscape-and-listview-portrait-functionality-in-one-control</link>
      <pubDate>Mon, 23 Dec 2013 15:14:51 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2013/12/23/the-autorotatinggridview-provides-gridview-landscape-and-listview-portrait-functionality-in-one-control/</guid>
      <description><![CDATA[In Windows Store apps version 8.1, a new UX guideline is to scroll vertically when in Portrait or...]]></description>
      <content:encoded><![CDATA[<p>In Windows Store apps version 8.1, a new UX guideline is to scroll vertically when in Portrait or Minimal width modes, and to scroll horizontally when in Landscape mode. The Visual Studio templates for Windows Store apps 8.0 provided two separate controls to render grid content in Landscape (GridView) and Snapped (ListView).</p>  <p>In the AdventureWorks app updated to 8.1, we considered using two separate controls as we had in the previous release, additionally using the ListView for Portrait mode. However the item data templates in Portrait mode were similar to the Landscape, not Minimal. There were also a few things about Portrait that were different from Minimal that made it hard to use the same ListView for both Portrait and Minimal visual states. Therefore, we were faced with having to use a GridView for Landscape, a ListView for Portrait and finally a separate ListView for Minimal. Yuck!</p>  <p>Enter the AutoRotatingGridView. This control is included in the AdventureWorks reference implementation updated to 8.1. This control listens to the its SizeChanged event and updates its layout between Landscape/Portrait/Minimal based on the windows size and shape. All you have to do is provide the appropriate values for:</p>  <ol>   <li>Item data template</li>    <li>Items panel</li>    <li>Group style</li> </ol>  <p>A really nice feature of the AutoRotatingGridView is that if you don’t provide any of the above values for Portrait or Minimal modes, the control will fall back to the value defined for Landscape.</p>  <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">awcontrols:AutoRotatingGridView</span>
    <span class="attr">ItemsSource</span><span class="kwrd">=&quot;{Binding Items}&quot;</span>
    <span class="attr">ItemTemplate</span><span class="kwrd">=&quot;{StaticResource ProductTemplate}&quot;</span>
    <span class="attr">MinimalItemTemplate</span><span class="kwrd">=&quot;{StaticResource ProductTemplateMinimal}&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">awcontrols:AutoRotatingGridView.ItemsPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">WrapGrid</span> <span class="attr">Orientation</span><span class="kwrd">=&quot;Vertical&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">awcontrols:AutoRotatingGridView.ItemsPanel</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">awcontrols:AutoRotatingGridView.PortraitItemsPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">WrapGrid</span> <span class="attr">Orientation</span><span class="kwrd">=&quot;Horizontal&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">awcontrols:AutoRotatingGridView.PortraitItemsPanel</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">awcontrols:AutoRotatingGridView.MinimalItemsPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Stretch&quot;</span> <span class="attr">Margin</span><span class="kwrd">=&quot;0,0,5,0&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ItemsPanelTemplate</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">awcontrols:AutoRotatingGridView.MinimalItemsPanel</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">awcontrols:AutoRotatingGridView</span><span class="kwrd">&gt;</span></pre>


<p>The above XAML defines an AutoRotatingGridView with an ItemTemplate, for Landscape mode, and a MinimalItemTemplate. When the control is in Portrait mode, the “ProductTemplate” ItemTemplate will be used since there is no PortraitItemTemplate specified. When the control is in Minimal, the control will use the “ProductTemplateMinimal” as specified by the MinimalItemTemplate property.</p>]]></content:encoded>
    </item>
    <item>
      <title>Prism for Windows Runtime: Validating User Input</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/prism-for-windows-runtime-validating-user-input</link>
      <pubDate>Tue, 07 May 2013 11:23:26 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2013/05/07/prism-for-windows-runtime-validating-user-input/</guid>
      <description><![CDATA[This is the fifth post in a series that walks you through creating a simple Windows Store app using...]]></description>
      <content:encoded><![CDATA[<p>This is the fifth post in a series that walks you through creating a simple Windows Store app using the Prism for Windows Runtime library. Please review the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/26/prism-for-windows-runtime-integrating-a-dependency-injection-container.aspx" target="_blank">fourth post</a> in the series for the steps necessary to create the basic app based on MvvmAppBase. </p>  <p>One feature that is missing from Windows Store app sdk is control support for user input validation. In WPF and Silverlight, you would expect to implement INotifyDataErrorInfo/IDataErrorInfo and controls such as TextBox and ComboBox would show an error state when appropriate. Unfortunately, these controls do not support these interfaces in the current release of .NET for Windows Store apps and Windows Runtime.</p>  <p>What is provided is support for DataAnnotations attributes. The Prism.StoreApps library provides some assistance in validating model objects that leverage these DataAnnotationson attributes. You will need to provide your own attached properties to appropriately style input controls. You can find an example error highlighting attached property in the AdventureWorks reference implementation (HighlightFormFieldOnErrors.PropertyErrors).</p>  <p>You can get the latest source on <a href="https://prismwindowsruntime.codeplex.com/">CodePlex</a>.</p>  <p>Let’s take a look at how you can use the Microsoft.Practices.Prism.StoreApps library to validate user input. </p>  <ol>   <li>Complete the Creating a basic implementation of the MVVM pattern walk through from the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/26/prism-for-windows-runtime-integrating-a-dependency-injection-container.aspx" target="_blank">previous post</a>.</li>    <li>Add a model class to the project: Add a class named Credential.</li>    <li>Use ValidatableBindableBase as the base class for the Credential class.</li>    <li>Add two string properties to the Credential class: Username and Password.      <br />Make sure to use a backing field and the SetProperty method provided by ValidatableBindableBase. The SetProperty method not only checks that the new value is different from the existing value before raising the PropertyChanged event, it also runs the validation logic.       <pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">string</span> _username;
<span class="kwrd">private</span> <span class="kwrd">string</span> _password;

<span class="kwrd">public</span> <span class="kwrd">string</span> Username
{
    get { <span class="kwrd">return</span> _username; }
    set { SetProperty(<span class="kwrd">ref</span> _username, <span class="kwrd">value</span>); }
}

<span class="kwrd">public</span> <span class="kwrd">string</span> Password
{
    get { <span class="kwrd">return</span> _password; }
    set { SetProperty(<span class="kwrd">ref</span> _password, <span class="kwrd">value</span>); }
}
    </pre>
    </li>

  <li>Add “Required” and “StringLength” DataAnnotations attributes to each property. 
    <pre class="csharpcode">[Required]
[StringLength(10)]<br /><span class="kwrd">public</span> <span class="kwrd">string</span> Username
{
    get { <span class="kwrd">return</span> _username; }
    set { SetProperty(<span class="kwrd">ref</span> _username, <span class="kwrd">value</span>); }
}

[Required]
[StringLength(20)]<br /><span class="kwrd">public</span> <span class="kwrd">string</span> Password
{
    get { <span class="kwrd">return</span> _password; }
    set { SetProperty(<span class="kwrd">ref</span> _password, <span class="kwrd">value</span>); }
}</pre>
    </li>

  <li>The model class is ready so let’s expose an instance of it on the SignInFlyoutViewModel.</li>

  <li>Add a class named SignInFlyoutViewModel to the ViewModels folder.</li>

  <li>Add a property to the SignInFlyoutViewModel that exposes the Credential model.&#160;&#160;&#160;&#160; <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> SignInFlyoutViewModel
{
    <span class="kwrd">public</span> SignInFlyoutViewModel()
    {
        UserCredential = <span class="kwrd">new</span> Credential();
    }
    <span class="kwrd">public</span> Credential UserCredential { get; set; }
}</pre>
    </li>

  <li>Use the ViewModelLocator.AutoWireViewModel=”True” attached property on the SignInFlyout page to associate this page (view) with the SignInFlyoutViewModel.</li>

  <li>Next, let’s add some controls to the view to bind to the Username and Password properties of the view model’s Credential property. We’ll also add some TextBlocks that will bind to any validation error messages.&#160;&#160;&#160;&#160; <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding UserCredential.Username, Mode=TwoWay}&quot;</span> <br />         <span class="attr">BorderBrush</span><span class="kwrd">=&quot;Black&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding UserCredential.Errors[Username], <br />                    Converter={StaticResource FirstErrorConverter}}&quot;</span> <br />         <span class="attr">Foreground</span><span class="kwrd">=&quot;Red&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding UserCredential.Password, Mode=TwoWay}&quot;</span> <br />         <span class="attr">BorderBrush</span><span class="kwrd">=&quot;Black&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding UserCredential.Errors[Password], <br />                    Converter={StaticResource FirstErrorConverter}}&quot;</span> <br />         <span class="attr">Foreground</span><span class="kwrd">=&quot;Red&quot;</span><span class="kwrd">/&gt;</span></pre>
    </li>

  <li>Note that the TextBlock controls bind to the Errors property of the UserCredential on the view model. The Errors property is provided by ValidatableBindableBase and is populated when a property fails validation. Since The Errors property returns a collection of string error messages for a given property name, we will use a value converter to show only the first message. Here is the source code for the FirstErrorConverter:
    <br />

    <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">sealed</span> <span class="kwrd">class</span> FirstErrorConverter : IValueConverter
{
    <span class="kwrd">public</span> <span class="kwrd">object</span> Convert(<span class="kwrd">object</span> <span class="kwrd">value</span>, <br />                          Type targetType, <br />                          <span class="kwrd">object</span> parameter, <br />                          <span class="kwrd">string</span> language)
    {
        ICollection&lt;<span class="kwrd">string</span>&gt; errors = <span class="kwrd">value</span> <span class="kwrd">as</span> ICollection&lt;<span class="kwrd">string</span>&gt;;
        <span class="kwrd">return</span> errors != <span class="kwrd">null</span> &amp;&amp; errors.Count &gt; 0 ? errors.ElementAt(0):<span class="kwrd">null</span>;
    }

    <span class="kwrd">public</span> <span class="kwrd">object</span> ConvertBack(<span class="kwrd">object</span> <span class="kwrd">value</span>, <br />                              Type targetType, <br />                              <span class="kwrd">object</span> parameter, <br />                              <span class="kwrd">string</span> language)
    {
        <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
    }
}</pre>
    </li>

  <li>To use this value converter as a static resource, remember to reference it in App.xaml:
    <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ResourceDictionary</span><span class="kwrd">&gt;</span>
    ...
    <span class="kwrd">&lt;</span><span class="html">converters:FirstErrorConverter</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;FirstErrorConverter&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">ResourceDictionary</span><span class="kwrd">&gt;</span></pre>
    </li>

  <li>Run the app and tap the “ShowFlyout” button. Enter some values in the two textboxes on the SignInFlyout. If you enter a string value that is too long for the field, or you remove the contents of either field, you will see the appropriate message in the TextBlocks.</li>

  <li>Next, add a button that calls UserCredential.ValidateProperties() that validates all properties of the model object instance.
    <pre class="csharpcode"><span class="kwrd">public</span> SignInFlyoutViewModel()
{
    UserCredential = <span class="kwrd">new</span> Credential();
    ValidateAll = <br />        <span class="kwrd">new</span> DelegateCommand(() =&gt; UserCredential.ValidateProperties());
}
<span class="kwrd">public</span> Credential UserCredential { get; set; }

<span class="kwrd">public</span> ICommand ValidateAll { get; set; }</pre>
    </li>

  <li>Add a button to the view that binds to the ValidateAll command. Remember that the background of the flyout is white according to the <a href="https://msdn.microsoft.com/en-us/library/windows/apps/Hh770544.aspx" target="_blank">UI Guidelines</a> so you will need to style your controls accordingly.

    <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">Command</span><span class="kwrd">=&quot;{Binding ValidateAll}&quot;</span> <br />        <span class="attr">Content</span><span class="kwrd">=&quot;Validate All&quot;</span> <br />        <span class="attr">Foreground</span><span class="kwrd">=&quot;Black&quot;</span><span class="kwrd">/&gt;</span></pre>
  </li>
</ol>]]></content:encoded>
    </item>
    <item>
      <title>Prism for Windows Runtime: Integrating a Dependency Injection Container</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/prism-for-windows-runtime-integrating-a-dependency-injection-container</link>
      <pubDate>Fri, 26 Apr 2013 15:13:35 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2013/04/26/prism-for-windows-runtime-integrating-a-dependency-injection-container/</guid>
      <description><![CDATA[This is the fourth post in a series that walk you through creating a simple Windows Store app using...]]></description>
      <content:encoded><![CDATA[<p>This is the fourth post in a series that walk you through creating a simple Windows Store app using the Prism for Windows Runtime library. Please review the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/25/prism-for-windows-runtime-creating-and-showing-a-flyout-using-the-flyoutservice-class.aspx" target="_blank">third post</a> in the series for the steps necessary to create the basic MVVM style app based on MvvmAppBase. </p>  <p>You can get the latest source on <a href="https://prismwindowsruntime.codeplex.com/" target="_blank">CodePlex</a>.</p>  <p>The following procedure shows how to integrate a dependency injection container into a Windows Store app that leverages MvvmAppBase from the Microsoft.Practices.Prism.StoreApps library.</p>  <ol>   <li>Add a reference to a Dependency Injection Container library. This walk through will use the Unity v3 container which is available via nugget (<a title="https://www.nuget.org/packages/Unity/" href="https://www.nuget.org/packages/Unity/">https://www.nuget.org/packages/Unity/</a>).</li>    <li>Add a private member varliable to the App class that will hold the container.      <pre class="csharpcode"><span class="kwrd">private</span> UnityContainer _container = <span class="kwrd">new</span> UnityContainer();</pre>
    </li>

  <li>Override the Resolve method on the App class so that it uses the container to resolve object instances from a type. 
    <pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">object</span> Resolve(Type type)
{
    <span class="kwrd">return</span> _container.Resolve(type);
}</pre>
    </li>

  <li>You can now remove the call to ViewModelLocator.Register in App.OnInitialize because the ViewModelLocator can use the container to resolve view model types. Register into the container any services that will need to be provided to view models via constructor injection. The StartPageViewModel needs an instance of IFlyoutService. The following code registers the three services provided by the MvvmAppBase. 
    <pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnInitialize(IActivatedEventArgs args)
{
    _container.RegisterInstance(NavigationService);
    _container.RegisterInstance(FlyoutService);
    _container.RegisterInstance(SessionStateService);
}</pre>
    </li>

  <li>Run the app. Notice that the button still causes the FlyoutService to show the SignInFlyout.</li>
</ol>]]></content:encoded>
    </item>
    <item>
      <title>Prism for Windows Runtime: Creating and showing a Flyout using the FlyoutService class</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/prism-for-windows-runtime-creating-and-showing-a-flyout-using-the-flyoutservice-class</link>
      <pubDate>Thu, 25 Apr 2013 15:46:49 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2013/04/25/prism-for-windows-runtime-creating-and-showing-a-flyout-using-the-flyoutservice-class/</guid>
      <description><![CDATA[This is the third post in a series that walk you through creating a simple Windows Store app using...]]></description>
      <content:encoded><![CDATA[<p>This is the third post in a series that walk you through creating a simple Windows Store app using the Prism for Windows Runtime library. Please review the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/25/prism-for-windows-runtime-creating-a-basic-implementation-of-the-mvvm-pattern.aspx" target="_blank">second post</a> in the series for the steps necessary to create the basic MVVM style app based on MvvmAppBase. </p>  <p>You can get the latest source on <a href="https://prismwindowsruntime.codeplex.com/" target="_blank">CodePlex</a>.</p>  <p>The following procedure shows how to create and show a Flyout by using the Microsoft.Practices.Prism.StoreApps library. You will discover how to use the FlyoutService class within a view model to show the Flyout, and how to add a SettingsCommand that will launch the Flyout from the Settings pane.</p>  <ol>   <li>Complete the Creating a basic implementation of the MVVM pattern walk through from the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/25/prism-for-windows-runtime-creating-a-basic-implementation-of-the-mvvm-pattern.aspx" target="_blank">previous post</a>.</li>    <li>First let’s create a Flyout. Add a blank page named SignInFlyout to the Views folder.      <br />The FlyoutService will use a default convention to look for Flyouts in the Views namespace where the name of the Flyout ends in “Flyout”.</li>    <li>Add a TextBlock to the Grid control in the SignInFlyout page.      <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">Background</span><span class="kwrd">=&quot;White&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">    &lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;Sign In!!!&quot;</span> <span class="attr">Foreground</span><span class="kwrd">=&quot;Black&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
    </pre>
    </li>

  <li>Change the SignInFlyout class to derive from the FlyoutView base class in the Microsoft.Practices.Prism.StoreApps library. Also, specify the width in the constructor. The StandardFlyoutSize class is defined in the Microsoft.Practices.Prism.StoreApps library. 
    <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">sealed</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> SignInFlyout : FlyoutView
{
    <span class="kwrd">public</span> SignInFlyout() : <span class="kwrd">base</span>(StandardFlyoutSize.Narrow)
    {
        <span class="kwrd">this</span>.InitializeComponent();
    }
}</pre>
  </li>

  <ol><!--StartFragment--></ol>

  <li>Update the SignInFlyout.xaml file so that the SignInFlyout view extends the FlyoutView base class in the Microsoft.Practices.Prism.StoreApps library. </li>

  <li>
    <pre class="csharpcode"> <span class="kwrd">&lt;</span><span class="html">Infrastructure:FlyoutView</span>
     <span class="attr">xmlns:Infrastructure</span><span class="kwrd">=&quot;using:Microsoft.Practices.Prism.StoreApps&quot;</span>
     ...
 <span class="kwrd">&lt;/</span><span class="html">Infrastructure:FlyoutView</span><span class="kwrd">&gt;</span>
    </pre>
  </li>

  <li>Next, let’s update the StartPage to show the SignInFlyout. Import the interfaces from the Microsoft.Practices.Prism.StoreApps namespace into the StartPageViewModel class. 
    <pre class="csharpcode"><span class="kwrd">using</span> Microsoft.Practices.Prism.StoreApps.Interfaces;</pre>
    </li>

  <li>Add a constructor to the StartPageViewModel class that takes a parameter of type IFlyoutService. 
    <pre class="csharpcode"><span class="kwrd">public</span> StartPageViewModel(IFlyoutService flyoutService)
{
}</pre>
    </li>

  <li>Notice that the StartPageViewModel class does not have a default constructor.</li>

  <li>Run the app. 
    <br /> You will receive a MissingMethodException that indicates that there isn't a parameterless constructor defined for the StartPageViewModel object. This occurs because the ViewModelLocator uses its default convention to locate the StartPageViewModel. The ViewModelLocator then used its default view model factory (Activator.CreateInstance) to construct an instance of the view model. In order for this to work, the type being constructed must possess a default constructor.</li>

  <li>Let’s provide the ViewModelLocator with a factory to create view model instances for the StartPage. Override the OnInitialize method in the App class to train the ViewModelLocator how to construct the StartPageViewModel instance. 
    <pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnInitialize(IActivatedEventArgs args)
{
    ViewModelLocator.Register(<span class="kwrd">typeof</span>(StartPage).ToString(), 
            () =&gt; <span class="kwrd">new</span> StartPageViewModel(FlyoutService));
}</pre>
    </li>

  <li>The Register method takes a string representation of the view type, and a delegate that returns the view model. You will see that the StartPageViewModel instance is created with the FlyoutService property of the MvvmAppBase class being passed to its constructor. Now that the ViewModelLocator knows how to construct the view model for the StartPage, it will not follow its convention for the StartPage.</li>

  <li>Add a Button to the StackPanel in StartPage that will show the SignInFlyout. 
    <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;Hello World!!!&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding FirstName, Mode=TwoWay}&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">Content</span><span class="kwrd">=&quot;ShowFlyout&quot;</span>
            <span class="attr">Command</span><span class="kwrd">=&quot;{Binding SignInCommand}&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
    </pre>
    </li>

  <li>Notice that the Button's Command property will be bound to a SignInCommand in the StartPageViewModel class.</li>

  <li>Import the System.Windows.Input namespace into the StartPageViewModel class. 
    <pre class="csharpcode"><span class="kwrd">using</span> System.Windows.Input;</pre>
    </li>

  <li>Add the SignInCommand property to the StartPageViewModel class. 
    <pre class="csharpcode"><span class="kwrd">public</span> ICommand SignInCommand { get; <span class="kwrd">private</span> set; }</pre>
  </li>

  <li>The property has a private setter because it will only be set internally.</li>

  <li>Set the SignInCommand property to an instance of a DelegateCommand that invokes the FlyoutService. 
    <pre class="csharpcode"><span class="kwrd">public</span> StartPageViewModel(IFlyoutService flyoutService)
{
     SignInCommand = <span class="kwrd">new</span> DelegateCommand(() =&gt; flyoutService.ShowFlyout(<span class="str">&quot;SignIn&quot;</span>));
}</pre>
    </li>

  <li>The DelegateCommand class, provided by the Microsoft.Practices.Prism.StoreApps library, is constructed with a delegate that will be invoked when the command is executed. Here, a lambda expression is specified that calls the ShowFlyout method of the FlyoutService class, passing the name of the Flyout.</li>

  <li>Run the app.</li>

  <li>Select the SignIn Button. 
    <br /> The SignInFlyout appears. Yeah!</li>

  <li>Next, let’s add an item to the Settings pane that will also show the SignInFlyout. Stop the app and override the GetSettingsCharmActionItems method in the App class. This method will be called when the CommandsRequested event of the SettingsPane class is raised. Add a SettingsCharmActionItem to the Settings pane that will open the SignInFlyout. 
    <pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> IList&lt;SettingsCharmActionItem&gt; GetSettingsCharmActionItems()
{
    <span class="kwrd">return</span> <span class="kwrd">new</span> List&lt;SettingsCharmActionItem&gt;{ <span class="kwrd">new</span> SettingsCharmActionItem(<span class="str">&quot;Sign In&quot;</span>, 
        () =&gt; FlyoutService.ShowFlyout(<span class="str">&quot;SignIn&quot;</span>))};
}</pre>
  </li>

  <li>The SettingsCharmActionItem class, provided by the Microsoft.Practices.Prism.StoreApps library, takes two constructor parameters. The first is a string title that will be displayed in the Settings pane. The second is an Action delegate that will be invoked when the user selects the “Sign In” item in the Settings pane.</li>

  <li>Run the app. Invoke the charms menu by making a horizontal edge gesture, swiping left with a finger or pointing device from the right of the screen.</li>

  <li>Select the Settings charm to display the Settings pane.</li>

  <li>Select the “Sign In” item. 
    <br /> The SignInFlyout appears. 

    <br /></li>
</ol>

<p>Next let’s <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/26/prism-for-windows-runtime-integrating-a-dependency-injection-container.aspx" target="_blank">integrate a dependency injection container into the app</a>.</p>

<ol></ol>]]></content:encoded>
    </item>
    <item>
      <title>Prism for Windows Runtime: Creating a basic implementation of the MVVM pattern</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/prism-for-windows-runtime-creating-a-basic-implementation-of-the-mvvm-pattern</link>
      <pubDate>Thu, 25 Apr 2013 11:38:56 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2013/04/25/prism-for-windows-runtime-creating-a-basic-implementation-of-the-mvvm-pattern/</guid>
      <description><![CDATA[This is the second blog post in a series that walk you through creating a simple Windows Store app...]]></description>
      <content:encoded><![CDATA[<p>This is the second blog post in a series that walk you through creating a simple Windows Store app using the Prism for Windows Runtime library. Please review the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/25/prism-for-windows-runtime.aspx" target="_blank">first post</a> in the series for the steps necessary to create the basic app based on MvvmAppBase. MvvmAppBase exposes several services including the FrameNavigationService which is necessary for both navigation and view model state persistence.</p>  <p>You can get the latest source on <a href="https://prismwindowsruntime.codeplex.com/" target="_blank">CodePlex</a>.</p>  <p>The following procedure shows how to create a basic implementation of the MVVM pattern by using the Microsoft.Practices.Prism.StoreApps library. You will also discover how view model instances can save their state to survive app termination.</p>  <ol>   <li>Complete the Creating a Hello World app walk through from the <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/25/prism-for-windows-runtime.aspx" target="_blank">previous post</a>.</li>    <li>Add a folder named ViewModels to the root folder of the Windows Store app project.</li>    <li>Add a new class to the ViewModels folder named StartPageViewModel.</li>    <li>Make the StartPageViewModel class public.</li>    <li>Add a FirstName property and backing field to the StartPageViewModel class.      <pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">string</span> _firstName;
<span class="kwrd">public</span> <span class="kwrd">string</span> FirstName
{
    get { <span class="kwrd">return</span> _firstName; }
    set { _firstName = <span class="kwrd">value</span>; }
}</pre>
    </li>

  <li>Import the types from the Microsoft.Practices.Prism.StoreApps library into the StartPageViewModel class.</li>

  <li>
    <pre class="csharpcode"><span class="kwrd">using</span> Microsoft.Practices.Prism.StoreApps;</pre>
    </li>

  <li>Update the StartPageViewModel class so that it derives from the ViewModel base class in the Microsoft.Practices.Prism.StoreApps library. 
    <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> StartPageViewModel : ViewModel</pre>
    </li>

  <li>By deriving the StartPageViewModel class from the ViewModel base class we can use the ViewModel class's implementation of INotifyPropertyChanged.</li>

  <li>Update the FirstName property to use the SetProperty method, from the Microsoft.Practices.Prism.StoreApps library, in the property setter. 
    <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> FirstName
{
    get { <span class="kwrd">return</span> _firstName; }
    set { SetProperty(<span class="kwrd">ref</span> _firstName, <span class="kwrd">value</span>); }
}</pre>
    </li>

  <li>The SetProperty method first checks to see if the new property value is identical to the old value. If the new value is different, the backing field is updated and the PropertyChanged event is raised with the property name as the event argument.</li>

  <li>Replace the contents of the Grid control in the StartPage view with a TextBox that will bind to the FirstName property of the StartPageViewModel class. 
    <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;Hello World!!!&quot;</span>
               <span class="attr">Style</span><span class="kwrd">=&quot;{StaticResource HeaderTextStyle}&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding FirstName, Mode=TwoWay}&quot; </span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre>
    </li>

  <li>The TextBox control will allow you to enter data. Since the Text property of the TextBox is bound to the FirstName property of the StartPageViewModel class with a TwoWay binding, updating the text in the TextBox control will update FirstName property and vice versa.</li>

  <li>Add the ViewModelLocator.AutoWireViewModel attached property to the Page control for the StartPage. 
    <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Page</span> <span class="attr">xmlns:Infrastructure</span><span class="kwrd">=&quot;using:Microsoft.Practices.Prism.StoreApps&quot;</span>
      <span class="attr">Infrastructure:ViewModelLocator</span>.<span class="attr">AutoWireViewModel</span><span class="kwrd">=&quot;True&quot;</span>
      ... <span class="kwrd">&gt;</span>
    ...
<span class="kwrd">&lt;/</span><span class="html">Page</span><span class="kwrd">&gt;</span></pre>
    </li>

  <li>The AutoWireViewModel attached property tells the ViewModelLocator object to create an instance of the view model that corresponds to this view and set it into the view's DataContext property. The ViewModelLocator object uses a default convention where it looks in the &quot;ViewModels&quot; namespace for a type whose name starts with the name of the view and ends with &quot;ViewModel&quot;.</li>

  <li>Run the app. Enter a value in the TextBox. The FirstName property of the StartPageViewModel instance will be updated.</li>

  <li>With the app running select the Suspend and shutdown menu option from the Debug Location toolbar in Visual Studio. 
    <br /> This feature is used to ensure that your app behaves as expected when Windows suspends or resumes it, or activates it after a suspend and shutdown sequence.</li>

  <li>Run the app. 
    <br /> Notice that the value you previously entered into the TextBox is no longer present.</li>

  <li>Stop the app and update the StartPageViewModel class so that the FirstName property is annotated with the [RestorableState] attribute. 
    <pre class="csharpcode">[RestorableState]
<span class="kwrd">public</span> <span class="kwrd">string</span> FirstName
{
    get { <span class="kwrd">return</span> _firstName; }
    set { SetProperty(<span class="kwrd">ref</span> _firstName, <span class="kwrd">value</span>); }
}</pre>
    </li>

  <li>Properties annotated with the [RestorableState] custom attribute will have their values saved when the app suspends, and will have their values restored when the app reactivates following termination.</li>

  <li>Run the app. With the app running select the Suspend and shutdown menu option from the Debug Location toolbar in Visual Studio.</li>

  <li>Run the app again. Notice that the value you previously entered into the TextBox survived termination.</li>
</ol>

<p>Next let’s take a look at how to <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/25/prism-for-windows-runtime-creating-and-showing-a-flyout-using-the-flyoutservice-class.aspx" target="_blank">create a Flyout and show it using the FlyoutService</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Prism for Windows Runtime</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/prism-for-windows-runtime</link>
      <pubDate>Wed, 24 Apr 2013 16:15:28 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2013/04/24/prism-for-windows-runtime/</guid>
      <description><![CDATA[As Blaine Wastell posted, we are about to release the patterns &amp; practices guidance for building...]]></description>
      <content:encoded><![CDATA[<p>As Blaine Wastell <a href="https://blogs.msdn.com/b/blaine/archive/2013/04/24/kona-guidance-is-now-prism-for-windows-runtime.aspx" target="_blank">posted</a>, we are about to release the patterns &amp; practices guidance for building Windows Store business apps. You may be thinking… “What is a business app?” and “How is a business app different than any other app?”. Well the simple answer is that a “business” app is expected to be well architected, maintainable, testable, and have high quality. Business apps may differ from simple content consumption apps in many ways. Business apps are more likely to need data validation. There is probably more state data that needs to survive suspension and termination. Also, it is more likely that business apps will be developed by teams of developers that want a decoupled architecture and a codebase that is maintainable and testable. </p>  <p>Basically, if you are interested in improving the quality and maintainability of your Windows Store apps, I recommend taking a look at this guidance. </p>  <p>You can get the latest source on <a href="https://prismwindowsruntime.codeplex.com/" target="_blank">CodePlex</a>.</p>  <p>This post is part 1 of a series that walks you through how to use the Prism for Windows Runtime library to create a Windows Store app. The Prism library will not only make your apps more testable and maintainable, I believe it will also make it easier to create Windows Store apps.</p>  <h3>Creating a Hello World app using Prism for Windows Runtime</h3>  <ol>   <li>Create a new C#-based Windows Store app named HelloWorld using the Blank App (XAML) Visual Studio project template. </li>    <li>Add a reference to the Microsoft.Practices.Prism.StoreApps library.</li>    <li>Add a folder named “Views” to the root folder of the Windows Store app project.      <br /> This app will use the FrameNavigationService class, provided by the Microsoft.Practices.Prism.StoreApps library, to navigate. The FrameNavigationService class's default convention is to locate pages in the &quot;Views&quot; namespace of the Windows Store app project. When the Navigate method of the FrameNavigationService class is called with a page token parameter, &quot;Page&quot; is appended to the page token. For example, if the Navigate method was called with &quot;Customer&quot; as the page token, the FrameNavigationService would look for a page named &quot;CustomerPage&quot; in the &quot;Views&quot; namespace.</li>    <li>Add a new Blank Page named “StartPage” to the Views folder.</li>    <li>Add a TextBlock control to the page's Grid control.&#160;&#160;&#160;&#160; <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&quot;Hello World!!!&quot;</span> <span class="attr">Style</span><span class="kwrd">=&quot;{StaticResource HeaderTextStyle}&quot;</span> <span class="kwrd">/&gt;</span></pre>
  </li>

  <li>Delete all of the contents of the App.xaml.cs file. This boilerplate functionality is now provided by the MvvmAppBase class.</li>

  <li>Add the following code to the App.xaml.cs file. 
    <pre class="csharpcode"><span class="kwrd">using</span> Microsoft.Practices.Prism.StoreApps;

<span class="kwrd">sealed</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> App : MvvmAppBase
{
    <span class="kwrd">public</span> App()
    {
        <span class="kwrd">this</span>.InitializeComponent();
    }
}</pre>
    </li>

  <li>Update the App.xaml file so that the App class derives from the MvvmAppBase class rather than the Application class. 
    <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Infrastructure:MvvmAppBase</span> <span class="attr">xmlns:Infrastructure</span><span class="kwrd">=&quot;using:Microsoft.Practices.Prism.StoreApps&quot;</span><span class="kwrd">&gt;</span>
   ...
<span class="kwrd">&lt;/</span><span class="html">Infrastructure:MvvmAppBase</span><span class="kwrd">&gt;</span><br /></pre>
  </li>

  <li>Add code to the App class to navigate to the StartPage. 
    <br /> The MvvmAppBase class provides several virtual methods that you can override to customize its behavior. However, MvvmAppBase provides the OnLaunchApplication abstract method for which you must provide an override. This method specifies what your app will do when it's launched. 

    <pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnLaunchApplication(LaunchActivatedEventArgs args)
{
    NavigationService.Navigate(<span class="str">&quot;Start&quot;</span>, <span class="kwrd">null</span>);
}<br /><font face="Segoe UI"><br />The MvvmAppBase has a NavigationService property that exposes the FrameNavigationService.</font></pre>
    </li>

  <li>Run the app. When the app runs you will see the StartPage with the “Hello World!!!” TextBlock.</li>
</ol>

<p>&#160;</p>

<p>Next let’s take a look at how to associate a view model to the StartPage view in my next post: <a href="https://blogs.msdn.com/b/francischeung/archive/2013/04/25/prism-for-windows-runtime-creating-a-basic-implementation-of-the-mvvm-pattern.aspx" target="_blank">Creating a basic implementation of the MVVM pattern</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>SHIPPED!!! Windows Phone Developer Guidance updated for Mango (WP SDK 7.1)</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/shipped-windows-phone-developer-guidance-updated-for-mango-wp-sdk-7-1</link>
      <pubDate>Mon, 02 Apr 2012 22:30:38 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2012/04/02/shipped-windows-phone-developer-guidance-updated-for-mango-wp-sdk-7-1/</guid>
      <description><![CDATA[We dramatically updated our guidance around Windows Phone development. Beyond recompiling our...]]></description>
      <content:encoded><![CDATA[<p>We dramatically updated our <a href="https://msdn.microsoft.com/en-us/library/gg477144.aspx" target="_blank">guidance around Windows Phone development</a>. Beyond recompiling our previous guidance against the Mango SDK, the latest guidance takes advantage of many Mango features such as fast app switching, background tasks, and new sensor APIs. We also did a fair amount of work showing how to create a layer of abstraction on top of the Windows Phone APIs that facilitates unit testing. </p>  <p>We split up our guidance into three parts:</p>  <ol>   <li><a href="https://msdn.microsoft.com/en-us/library/hh848247.aspx" target="_blank">Developing a Windows Phone Application using the MVVM Pattern</a>      <br />This guidance walks you through building a simple Windows Phone application using CodeBehind files. The guidance then shows you how the same app can be much more unit testable when built using the MVVM pattern. </li>    <li><a href="https://msdn.microsoft.com/en-us/library/gg490765.aspx" target="_blank">A Case Study for Building Advanced Windows Phone Applications</a>      <br />This guidance takes an in-depth look at how to write an advanced Windows Phone application, using many features of Mango. Unit testability was an important factor that guided the design of this application.</li>    <li><a href="https://msdn.microsoft.com/en-us/library/hh830877.aspx" target="_blank">Building Testable Windows Phone Applications</a>      <br />Taking the work on unit testability from the above guidance, this guidance provides shorter samples of how to build unit testable Windows Phone applications.</li> </ol>  <p>Please take a look and send me your feedback.</p>]]></content:encoded>
    </item>
    <item>
      <title>Running Windows Phone Unit Tests via MSBuild</title>
      <link>https://docs.microsoft.com/archive/blogs/francischeung/running-windows-phone-unit-tests-via-msbuild</link>
      <pubDate>Tue, 03 Jan 2012 15:10:24 GMT</pubDate>
      <dc:creator><![CDATA[fcheung]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/francischeung/2012/01/03/running-windows-phone-unit-tests-via-msbuild/</guid>
      <description><![CDATA[I’m a big fan of TDD and continuous integration, so when I first started development on Windows...]]></description>
      <content:encoded><![CDATA[<p>I’m a big fan of TDD and continuous integration, so when I first started development on Windows Phone 7, I quickly found <a href="https://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/" target="_blank">Jeff Wilcox’s Silverlight Unit Test Framework</a>. This unit testing framework provides a nice way to write MSTest style unit tests and have them run on a device/emulator. The piece that was missing for me was the ability to capture the results of the unit test run and include these results with an automated run of MSBuild. If any unit tests fail, the MSBuild run should fail.</p>  <p>I’ve seen several blog posts on this topic but none that gave me an end to end solution. Armed with the latest Mango bits and the CoreCon 10 WP7 API, this task was easier than I thought. Here’s how it works…</p>  <ol>   <li>Capture the unit test run with custom LogProvider that writes the test run messages to a file in isolated storage. </li>    <li>Custom MSBuild task that deploys test xap file to emulator, installs the application, runs the application, waits for a configured number of seconds and harvests the results of item #1 above. </li> </ol>  <p>Let’s start with the custom LogProvider:</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">public</span> <span style="color: #0000ff">class</span> FileLogProvider : LogProvider<br />{<br />    <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> TESTRESULTFILENAME = <span style="color: #006080">@&quot;TestResults\testresults.txt&quot;</span>;<br />    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> ProcessRemainder(LogMessage message)<br />    {<br />        <span style="color: #0000ff">base</span>.ProcessRemainder(message);<br />        AppendToFile(message);<br />    }<br /><br />    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> Process(LogMessage logMessage)<br />    {<br />        AppendToFile(logMessage);<br />    }<br /><br />    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> AppendToFile(LogMessage logMessage)<br />    {<br />        UTF8Encoding encoding = <span style="color: #0000ff">new</span> UTF8Encoding();<br />        var carriageReturnBytes = encoding.GetBytes(<span style="color: #0000ff">new</span>[] { <span style="color: #006080">'\r'</span>, <span style="color: #006080">'\n'</span> });<br /><br />        <span style="color: #0000ff">using</span> (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())<br />        {<br />            <span style="color: #0000ff">if</span> (!store.DirectoryExists(<span style="color: #006080">&quot;TestResults&quot;</span>))<br />            {<br />                store.CreateDirectory(<span style="color: #006080">&quot;TestResults&quot;</span>);<br />            }<br />            <span style="color: #0000ff">using</span> (IsolatedStorageFileStream isoStream =<br />                store.OpenFile(TESTRESULTFILENAME, FileMode.Append))<br />            {<br />                var byteArray = encoding.GetBytes(logMessage.Message);<br />                isoStream.Write(byteArray, 0, byteArray.Length);<br />                isoStream.Write(carriageReturnBytes, 0, carriageReturnBytes.Length);<br />            }<br />        }<br />    }<br />}</pre>

  <br /></div>

<div id="codeSnippetWrapper">This class basically receives log messages and appends them to the TestResults\testresults.txt file in isolated storage. Pretty straightforward. You’ll need to reference <a href="https://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/" target="_blank">Jeff Wilcox’s Silverlight Unit Test Framework</a> in order to resolve LogProvider.</div>

<div>&#160;</div>

<div>You use FileLogProvider in your test project. Here is an example MainPage.xaml.cs</div>

<div>&#160;</div>

<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">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> MainPage : PhoneApplicationPage<br />{<br />    <span style="color: #008000">// Constructor</span><br />    <span style="color: #0000ff">public</span> MainPage()<br />    {<br />        <span style="color: #0000ff">this</span>.InitializeComponent();<br />        LogProvider fileLogProvider = <span style="color: #0000ff">new</span> FileLogProvider();<br />        var settings = UnitTestSystem.CreateDefaultSettings();<br />        settings.LogProviders.Add(fileLogProvider);<br /><br />        Content = UnitTestSystem.CreateTestPage(settings);<br />        BackKeyPress += (x, xe) =&gt; xe.Cancel = (Content <span style="color: #0000ff">as</span> IMobileTestPage).NavigateBack();<br />    }<br />}</pre>

  <br /></div>

<p>Great! Now that we’ve captured the test run results on the phone, how do we get it to the server? I’ve heard people use web services but I found using the CoreCon API worked fine. </p>

<p>My custom MSBuild task does the following:</p>

<ol>
  <li>Connects to the emulator </li>

  <li>Installs/Reinstalls the application </li>

  <li>Launches the application </li>

  <li>Waits a specified number of seconds for the application to finish running tests. </li>

  <li>Pulls the TestResults\testresults.txt file from the application’s isolated storage and copies it locally. </li>

  <li>Examines the contents of the test results for failing unit test. </li>
</ol>

<p>Here is the source for my custom MSBuild task:</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"><p><span style="color: #0000ff">namespace</span> MSBuildTasks<br />{<br />    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RunWP7UnitTestsInEmulator : Task<br />    {<br />        <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span> defaultNumberOfMiliSecondsToProcess = 50000;<br /><br />        [Required]<br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> PathToUnitTestXapFile { get; set; }<br /><br />        [Required]<br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> ProductGuid { get; set; }<br /><br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> NumberOfMilliSecondsToProcess { get; set; }<br /><br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">bool</span> Execute()<br />        {<br />            <span style="color: #0000ff">if</span> (NumberOfMilliSecondsToProcess == 0)<br />            {<br />                Log.LogMessage(<span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;Using default processing time: {0}&quot;</span>, defaultNumberOfMiliSecondsToProcess));<br />                NumberOfMilliSecondsToProcess = defaultNumberOfMiliSecondsToProcess;<br />            }<br /><br />            Log.LogMessage(<span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;NumberOfMilliSecondsToProcess: {0}&quot;</span>, NumberOfMilliSecondsToProcess));<br /><br />            Log.LogMessage(<span style="color: #006080">&quot;Running tests in XAP: &quot;</span> + PathToUnitTestXapFile);<br />            var productGuid = <span style="color: #0000ff">new</span> Guid(ProductGuid);<br /><br />            var emulator = GetWP7Emulator();<br />            Log.LogMessage(<span style="color: #006080">&quot;Connecting to Emulator.&quot;</span>);<br />            emulator.Connect();<br />            Log.LogMessage(<span style="color: #006080">&quot;After call to Connect().&quot;</span>);<br /><br />            <span style="color: #008000">//Deploy application</span><br />            <span style="color: #0000ff">if</span> (emulator.IsApplicationInstalled(productGuid))<br />            {<br />                emulator.GetApplication(productGuid).Uninstall();<br />            }<br /><br />            emulator.InstallApplication(productGuid, productGuid, <span style="color: #006080">&quot;NormalApp&quot;</span>, <span style="color: #0000ff">null</span>, PathToUnitTestXapFile);<br /><br />            <span style="color: #008000">//Run application</span><br />            var application = emulator.GetApplication(productGuid);<br />            application.Launch();<br /><br /><br /></p><p>&#160;</p><p>            Thread.Sleep(NumberOfMilliSecondsToProcess);<br /><br />            <span style="color: #008000">//Get Results from Isolated Store on device</span><br />            var isostorefile = application.GetIsolatedStore();<br />            var localTestResultFileName = <span style="color: #006080">&quot;EmulatorTestResults-&quot;</span> + productGuid + <span style="color: #006080">&quot;.txt&quot;</span>;<br />            isostorefile.ReceiveFile(<span style="color: #006080">@&quot;\TestResults\testresults.txt&quot;</span>, localTestResultFileName, <span style="color: #0000ff">true</span>);<br /><br />            var testResults = File.ReadAllText(localTestResultFileName);<br /><br />            <span style="color: #0000ff">if</span> (testResults.Contains(<span style="color: #006080">&quot;Exception:&quot;</span>))<br />            {<br />                Log.LogError(<span style="color: #006080">&quot;Failing test found. Look for exception in: &quot;</span> + localTestResultFileName);<br />                <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;<br />            }<br /><br />            Log.LogMessage(<span style="color: #006080">&quot;All tests passed.&quot;</span>);<br /><br />            emulator.Disconnect();<br /><br />            <span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span>;<br />        }<br /><br />        <span style="color: #0000ff">private</span> Device GetWP7Emulator()<br />        {<br />            var manager = <span style="color: #0000ff">new</span> DatastoreManager(CultureInfo.CurrentUICulture.LCID);<br />            var wp7Platform = manager.GetPlatforms().Single(platform =&gt; platform.Name == <span style="color: #006080">&quot;Windows Phone 7&quot;</span>);<br />            <span style="color: #0000ff">return</span> wp7Platform.GetDevices().Single(device =&gt; device.Name == <span style="color: #006080">&quot;Windows Phone Emulator&quot;</span>);<br />        }<br />    }<br />}</p></pre>
  </div>

  <div>&#160;</div>

  <div>You’ll need to reference CoreCon (Microsoft.SmartDevice.Connectivity.dll). On my 64 bit machine, I found the dll here:</div>

  <div>C:\Program Files (x86)\Common Files\microsoft shared\Phone Tools\CoreCon\10.0\Bin\Microsoft.Smartdevice.Connectivity.dll
    <br /></div>

  <div>Finally, I just call my build task in an msbuild proj file:</div>

  <div>&#160;</div>
</div>

<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">&lt;</span><span style="color: #800000">Project</span> <span style="color: #ff0000">DefaultTargets</span><span style="color: #0000ff">=&quot;Test&quot;</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/developer/msbuild/2003&quot;</span> <span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">UsingTask</span> <span style="color: #ff0000">TaskName</span><span style="color: #0000ff">=&quot;MSBuildTasks.RunWP7UnitTestsInEmulator&quot;</span> <br />        <span style="color: #ff0000">AssemblyFile</span><span style="color: #0000ff">=&quot;MSBuildTasks.dll&quot;</span><span style="color: #0000ff">/&gt;</span><br /><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">PropertyGroup</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">SourceFilesPath</span><span style="color: #0000ff">&gt;</span>$(MSBuildProjectDirectory)\..\Source\<span style="color: #0000ff">&lt;/</span><span style="color: #800000">SourceFilesPath</span><span style="color: #0000ff">&gt;</span><br /><br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">PropertyGroup</span><span style="color: #0000ff">&gt;</span><br /><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemGroup</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">SolutionItemsToBuild</span> <span style="color: #ff0000">Include</span><span style="color: #0000ff">=&quot;$(SourceFilesPath)\**\*.sln&quot;</span> <span style="color: #0000ff">/&gt;</span><br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemGroup</span><span style="color: #0000ff">&gt;</span><br /><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Target</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">=&quot;Build&quot;</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">MSBuild</span> <span style="color: #ff0000">Projects</span><span style="color: #0000ff">=&quot;%(SolutionItemsToBuild.Identity)&quot;</span> <span style="color: #ff0000">Targets</span><span style="color: #0000ff">=&quot;Build&quot;</span><span style="color: #0000ff">/&gt;</span><br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Target</span><span style="color: #0000ff">&gt;</span><br /><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Target</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">=&quot;Test&quot;</span> <span style="color: #ff0000">DependsOnTargets</span><span style="color: #0000ff">=&quot;Build&quot;</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">RunWP7UnitTestsInEmulator</span> <span style="color: #ff0000">NumberOfMilliSecondsToProcess</span><span style="color: #0000ff">=&quot;50000&quot;</span> <br /><span style="color: #ff0000">            PathToUnitTestXapFile</span><span style="color: #0000ff">=&quot;$(SourceFilesPath)\MyWP7Project.Tests\Bin\Debug\MyWP7Project.Tests.xap&quot;</span> <br />            <span style="color: #ff0000">ProductGuid</span><span style="color: #0000ff">=&quot;MyWP7ProjectProductGuid&quot;</span> <span style="color: #0000ff">/&gt;</span><br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Target</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Project</span><span style="color: #0000ff">&gt;</span></p></pre>

  <br /></div>

<p>You’ll need to replace the PathToUnitTexstXapFile and ProductGuid, but this proj file should build all solutions in the “Source” folder and then test the Windows Phone unit tests specified in the Test target.</p>

<p>I’ve had this integrated into my continuous integration server and it works great. I need to run the CI server in interactive mode because launching the emulator on my server box always pops a dialog complaining about the graphics processing unit configuration. I just keep an emulator instance open to avoid this popup.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/57/73/metablogapi/3364.image_55AB113F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-57-73-metablogapi/3364.image_5F00_55AB113F.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/00/57/73/metablogapi/4857.image_thumb_29FA4743.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-57-73-metablogapi/4857.image_5F00_thumb_5F00_29FA4743.png" width="422" height="210" /></a></p>]]></content:encoded>
    </item>
  </channel>
</rss>