<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7294975990662761436</id><updated>2011-10-11T10:40:43.775-07:00</updated><category term='Attached properties'/><category term='Microsoft'/><category term='installation'/><category term='Accessibility'/><category term='Button'/><category term='listview'/><category term='MixModes Synergy 2011'/><category term='Behavior Handler Pattern'/><category term='boost'/><category term='AJAX'/><category term='CodeProject'/><category term='Dependency Properties'/><category term='Software Testing'/><category term='Active Accessibility'/><category term='Tutorial'/><category term='Mercurial'/><category term='sync'/><category term='ASP.NET MVC'/><category term='Automated UI Testing'/><category term='Spy++'/><category term='ASP.NET'/><category term='Photoshop'/><category term='Http Handlers'/><category term='MongoDB'/><category term='AutomationPeer'/><category term='Calculator Automation'/><category term='MixModes Synergy 2010'/><category term='Custom Windows'/><category term='Source Code Control Systems'/><category term='Perforce'/><category term='compilation'/><category term='AutomationElement'/><category term='Synergy Toolkit For Windows Phone 7'/><category term='Book'/><category term='scons'/><category term='Design Patterns'/><category term='Rounded rectangle'/><category term='linux'/><category term='BasePattern'/><category term='checkbox'/><category term='Expression Blend cannot create an instance of user control'/><category term='jQuery'/><category term='fixed width listview'/><category term='of'/><category term='Subversion'/><category term='cannot'/><category term='Localization'/><category term='WPF Behaviors'/><category term='Photoshop Styles and Gradients'/><category term='InvokePattern'/><category term='WPF Handlers'/><category term='ExpandCollapsePattern'/><category term='instance'/><category term='PatternInterface'/><category term='Web 2.0'/><category term='OSX'/><category term='create'/><category term='MixModes'/><category term='Paths'/><category term='AjaxPro'/><category term='an'/><category term='Markup extensions'/><category term='Windows Phone 7'/><category term='ASP.NET AJAX'/><category term='UI Automation'/><category term='pcre++'/><category term='filesystem'/><category term='user control'/><category term='Icon'/><category term='Value converters'/><category term='Control Patterns'/><category term='Data Binding'/><category term='Expression Trees'/><category term='Behavior Driven Development'/><category term='Dynamic value converters'/><category term='column header'/><category term='framework'/><category term='Cross'/><category term='WPF Control Development Unleashed'/><category term='WeakReference'/><category term='Vector mask'/><category term='Pen tool'/><category term='WPF'/><category term='TreeWalker'/><category term='Silverlight'/><category term='.NET'/><title type='text'>Ashish's Blogging Space</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-3522857189994453495</id><published>2011-07-08T19:39:00.000-07:00</published><updated>2011-07-08T20:11:36.705-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scons'/><category scheme='http://www.blogger.com/atom/ns#' term='OSX'/><category scheme='http://www.blogger.com/atom/ns#' term='MongoDB'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='installation'/><category scheme='http://www.blogger.com/atom/ns#' term='compilation'/><category scheme='http://www.blogger.com/atom/ns#' term='boost'/><category scheme='http://www.blogger.com/atom/ns#' term='pcre++'/><title type='text'>Setting up MongoDB on OSX</title><content type='html'>Recently I successfully downloaded and installed MongoDB on my mac. I am a Windows developer dwelling in the world of linux programming, so I wanted to blog about my experience as it may be helpful to other fellow devs who are new to linux as well.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Most of the steps below are refinement / explanation of http://www.mongodb.org/display/DOCS/Building+for+OS+X&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Step 1 - Download MongoDB server - From mongodb.org website download MongoDB server and untar the files in some folder (MongoDB_Server).&lt;/li&gt;&lt;li&gt;Step 2 - Create a folder /data/db in your root. MongoDB server uses this path to store the database(s).&lt;/li&gt;&lt;li&gt;Step 3- Download MongoDB client - From mongodb.org download a compatible client (same version as the server) and untar the files in client folder (MongoDB_Client)&lt;/li&gt;&lt;li&gt;Step 4 - If you haven't done so far, you must download package manager on OSX called homebrew. A package manager on linux is an application that makes it dead simple to download other applications and install them on your system. To download homebrew open a shell window and type: curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local&lt;/li&gt;&lt;li&gt;Step 5 - Download boost C++ library - Execute: brew install boost&lt;/li&gt;&lt;li&gt;Step 6 - Download scons (Makefile executor) - Execute: brew install scons&lt;/li&gt;&lt;li&gt;Step 7 - Download pcre++ (Perl regular expression lib) - Execute: brew install pcre++&lt;/li&gt;&lt;li&gt;Step 8 - Build client - Navigate to the client folder and simply type: scons&lt;/li&gt;&lt;li&gt;Step 9 - Start server - Open a new shell window and navigate to server folder's bin subfolder and type: mangod. This should start the server !&lt;/li&gt;&lt;li&gt;Step 10 - Test client - Navigate to client folder and execute: ./clientTest (this should run a simple client test)&lt;/li&gt;&lt;li&gt;Step 11 - Write your own test: In the client folder's client/example subfolder, create a test program with code from: http://www.mongodb.org/pages/viewpage.action?pageId=133415 and name it test.cpp&lt;/li&gt;&lt;li&gt;Step 12 - Now navigate to root client folder and execute: g++ -o test client/examples/test.cpp -I mongo -L. -lmongoclient -lpthread -lboost_thread-mt -lboost_filesystem-mt -lboost_system-mt&lt;/li&gt;&lt;li&gt;Step 13: Last step should compile your code and output test binary. Simply execute this binary to verify client code ! Ensure that your server is running all this time...&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-3522857189994453495?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/3522857189994453495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=3522857189994453495' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/3522857189994453495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/3522857189994453495'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2011/07/setting-up-mongodb-on-osx.html' title='Setting up MongoDB on OSX'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-5769273753850812039</id><published>2011-05-01T20:15:00.001-07:00</published><updated>2011-05-01T20:15:04.547-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='UI Automation'/><category scheme='http://www.blogger.com/atom/ns#' term='user control'/><category scheme='http://www.blogger.com/atom/ns#' term='Book'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF Control Development Unleashed'/><title type='text'>My favorite WPF book of all times–WPF Control Development Unleashed</title><content type='html'>&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://www.amazon.com/WPF-Control-Development-Unleashed-Experiences/dp/0672330334/ref=ntt_at_ep_dpi_1" target="_blank"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" border="0" align="left" src="http://ecx.images-amazon.com/images/I/41zIyhX1I3L._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA300_SH20_OU01_.jpg" /&gt;&lt;/a&gt;Whenever I pick up a technical book to acquaint myself with a particular technology I personally look for the philosophy which makes that particular technology relevant in the field. After all if you just want an introduction or code samples, internet is a valuable resource why bother buying a book, right?&lt;/p&gt;  &lt;p align="justify"&gt;About an year and half ago I was put in-charge of UI design of our product using Windows Presentation Foundation (WPF) and started looking out for resources on the web, in the libraries and books. I finally stumbled upon this masterpiece by Pavan Podila and Kevin Hoffman called WPF Control Development Unleashed.&lt;/p&gt;  &lt;p align="justify"&gt;I really loved how the book introduces the philosophy of WPF UI design and the diverse visual class structure in the opening chapters. Most admirably how authors provide insight and emphasis into code reuse, UI templating, extending existing controls using attached properties before jumping on to custom controls. In fact many examples in the book illustrate how extending existing UI controls result in more maintainable code without much effort.&lt;/p&gt;  &lt;p align="justify"&gt;The book covers a very broad spectrum of UI development in WPF such as building custom panels, UI virtualization, advanced scrolling, 2D and 3D animations, pixel shader effects and even rare topics such as UI automation which are skipped in many other books I have read. The book is pure joy to read and I have personally read this book about three times if not more.&lt;/p&gt;  &lt;p align="justify"&gt;I have been successful in applying concepts from the book into our product – &lt;a href="http://us.blackberry.com/apps-software/desktop/" target="_blank"&gt;BlackBerry Desktop Software&lt;/a&gt;, and so have my team. I highly recommend this book for any serious WPF developer who can gain end to end insight into the technology from this fabulous resource.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-5769273753850812039?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/5769273753850812039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=5769273753850812039' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5769273753850812039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5769273753850812039'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2011/05/my-favorite-wpf-book-of-all-timeswpf.html' title='My favorite WPF book of all times–WPF Control Development Unleashed'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-1141419670348940762</id><published>2011-01-30T13:41:00.001-08:00</published><updated>2011-01-30T13:51:08.028-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Button'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Behavior Driven Development'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes Synergy 2011'/><category scheme='http://www.blogger.com/atom/ns#' term='CodeProject'/><category scheme='http://www.blogger.com/atom/ns#' term='Attached properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows Phone 7'/><category scheme='http://www.blogger.com/atom/ns#' term='Dependency Properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Synergy Toolkit For Windows Phone 7'/><category scheme='http://www.blogger.com/atom/ns#' term='Data Binding'/><title type='text'>MixModes Synergy Toolkit for Windows Phone 7</title><content type='html'>&lt;p align="justify"&gt;Synergy is a platform toolkit that unleashes the power of WPF, Silverlight and Windows Phone 7 platforms. In this blog I will discuss the Windows 7 phone part of this library and how it helps to somehow converge development practices to that of WPF and leverage data binding capabilities.&lt;/p&gt;  &lt;p align="justify"&gt;Synergy toolkit can be accessed at its &lt;a href="http://mixmodessynergy.codeplex.com/" target="_blank"&gt;codeplex home&lt;/a&gt; where Santa (myself) keeps delivering new gifts and wishes everyday. I have released v1 of Windows Phone 7 library in the &lt;a href="http://mixmodessynergy.codeplex.com/releases/view/60078" target="_blank"&gt;downloads section&lt;/a&gt;.&lt;/p&gt;  &lt;p align="justify"&gt;For a background on WPF synergy toolkit, you can refer to my previous blog &lt;a href="http://ashishkaila.blogspot.com/2010/12/introducing-mixmodes-synergy-2010.html" target="_blank"&gt;here&lt;/a&gt;. I also wrote a docking windows framework in WPF edition of synergy that you can refer &lt;a href="http://www.codeproject.com/KB/WPF/WPFDockingToolkit.aspx" target="_blank"&gt;here&lt;/a&gt; and a window theming article &lt;a href="http://www.codeproject.com/KB/WPF/CustomWPFWindow.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p align="justify"&gt;You can follow me on twitter &lt;a href="http://twitter.com/ashishkaila" target="_blank"&gt;@ashishkaila&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Without further adieu let me walk you through the features of the v1 release.&lt;/p&gt;  &lt;h3 align="justify"&gt;Base Framework for Windows Phone 7 Development&lt;/h3&gt;  &lt;p align="justify"&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;/p&gt;  &lt;h4 align="justify"&gt;Commanding Support&lt;/h4&gt;  &lt;p align="justify"&gt;CommandBase class provides a flexible implementation for custom commands. This class works on an Action&amp;lt;object&amp;gt; instance for command invocation and an optional Predicate&amp;lt;object&amp;gt; for command execution evaluation. If the predicate is not specified, it is assumed that command can be executed anytime. Simply speaking, one can instantiate CommandBase class as follows: &lt;/p&gt;  &lt;p align="justify"&gt;CommandBase myCommand = new CommandBase(arg=&amp;gt;Foo(arg), arg=&amp;gt;CanFoo(arg));&lt;/p&gt;  &lt;p align="justify"&gt;Moreover since WP7 and Silverlight do not provide out of the box capability to bind &lt;/p&gt;  &lt;h4 align="justify"&gt;Dependency System Enhancements&lt;/h4&gt;  &lt;p align="justify"&gt;Several enhancements in dependency system have been provided that helps developers tap easily into the framework for advanced operations related to binding and dependency properties. These enhancements are as follows:&lt;/p&gt;  &lt;h5 align="justify"&gt;Observable Binding&lt;/h5&gt;  &lt;p align="justify"&gt;ObservableBinding class as the name suggests observes a binding for value changes and provides the most recent value for the binding. This class is very useful within custom behaviors and trigger actions where data context of associated object does not propagate to these entities. This is so because Behaviors and Triggers are attached properties within the static Interaction class (declared in System.Windows.Interactivity assembly) and are therefore detached from the dependency system.&lt;/p&gt;  &lt;p align="justify"&gt;By declaring a dependency property of type Binding and using ObservableBinding within a Behavior/TriggerAction you can both hook into the dependency property system of associated object as well as evaluate the most recent value of the binding. &lt;/p&gt;  &lt;p align="justify"&gt;For instance EventToCommand trigger action defines a dependency property Command of type Binding:&lt;/p&gt;  &lt;p align="justify"&gt;public static DependencyProperty CommandProperty = DependencyProperty.Register(&amp;quot;Command&amp;quot;,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof (Binding),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof (EventToCommand),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyMetadata(null, OnCommandChanged));&lt;/p&gt;  &lt;p align="justify"&gt;It also declares an ObservableBinding for the command:&lt;/p&gt;  &lt;p align="justify"&gt;private readonly ObservableBinding _observableCommandBinding = new ObservableBinding();&lt;/p&gt;  &lt;p align="justify"&gt;This _observableCommandBinding member will provide us with the latest value of Binding exposed by Command property. &lt;/p&gt;  &lt;p align="justify"&gt;There are certain rules to ensure that ObservableBinding works as expected for Binding properties. Basically anytime Binding property changes, we have to unhook from the old Binding and hook into the new binding. This is done in the OnCommandChanged method which is called when Binding property is changed (that is the actual Binding property and not the value of the Binding):&lt;/p&gt;  &lt;p align="justify"&gt;private static void OnCommandParameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)   &lt;br /&gt;{    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; EventToCommand eventToCommand = d as EventToCommand;&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&amp;#160;&amp;#160; if (eventToCommand == null)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&amp;#160;&amp;#160; eventToCommand._observableCommandParameterBinding.Detach();   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if ((e.NewValue != null) &amp;amp;&amp;amp; (eventToCommand.AssociatedObject != null))    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; eventToCommand._observableCommandParameterBinding.Attach(eventToCommand.Command eventToCommand.AssociatedObject);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;Also when associated object is initially attached to the TriggerAction / Behavior, we need to attach to the ObservableBinding:&lt;/p&gt;  &lt;p align="justify"&gt;protected override void OnAttached()   &lt;br /&gt;{    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; base.OnAttached();&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&amp;#160;&amp;#160; if (Command != null)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _observableCommandBinding.Attach(Command, AssociatedObject);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;If you skip the above step, the initial value of Binding will not be tracked by ObservableBinding.&lt;/p&gt;  &lt;h5 align="justify"&gt;ObservableDependencyProperty&lt;/h5&gt;  &lt;p align="justify"&gt;ObservableDependencyProperty on the other hand provides the ability to track changes in dependency property declared in another DependencyObject by way of event notifications. The constructor of ObservableDependencyProperty takes two parameters: the string representing the name of the dependency property to observe&amp;#160; and a delegate of type DependencyPropertyChangedEventHandler that will be called when the dependency property changes:&lt;/p&gt;  &lt;p align="justify"&gt;ObservableDependencyProperty _verticalScrollChange = new ObservableDependencyProperty(&amp;quot;VerticalOffset&amp;quot;, OnVerticalScroll);&lt;/p&gt;  &lt;p align="justify"&gt; To track changes in dependency property of the actual DependencyObject, ObservableDependencyProperty instance must be attached to it via AddValueChanged method:&lt;/p&gt;  &lt;p align="justify"&gt;_verticalScrollChange.AddValueChanged(_scrollViewer);&lt;/p&gt;  &lt;p align="justify"&gt;Similarly to detach or stop property change tracking, RemoveValueChanged method may be called:&lt;/p&gt;  &lt;p align="justify"&gt;_verticalScrollChange.RemoveValueChanged();&lt;/p&gt;  &lt;h3 align="justify"&gt;Complete MVVM Framework&lt;/h3&gt;  &lt;p align="justify"&gt;Custom view models can be implemented by simply inheriting from the base class ViewModelBase. To raise PropertyChanged event, a type safe RaisePropertyChanged method can be called with an expression containing your property reference, e.g.:&lt;/p&gt;  &lt;p align="justify"&gt;RaisePropertyChanged(x=&amp;gt;MyProperty);&lt;/p&gt;  &lt;p align="justify"&gt;ViewModelBase also contains a Navigate method that can navigate the phone to a bound view performing data binding behind the scenes (more on this in the next section), e.g.:&lt;/p&gt;  &lt;p align="justify"&gt;MyViewModel viewModel = new MyViewModel();   &lt;br /&gt;viewModel.Navigate(); // Note: For this to work, your application must inherit from PhoneApplication class (see below)    &lt;br /&gt;&lt;/p&gt;  &lt;h3 align="justify"&gt;Easier Navigation via Declarative View-ViewModel Bindings&lt;/h3&gt;  &lt;p align="justify"&gt;In WPF DataTemplates could bind a ViewModel to View on an application level. This binding enabled runtime view generation within ContentPresenter. I wanted to extend the same idea to Windows Phone 7 screen navigation since url based navigation within an application seems error prone and passing query parameters is tedious. &lt;/p&gt;  &lt;p align="justify"&gt;ViewSelector class provides this declarative binding capabilities in conjunction with ViewBinding class. Basically in your application resources you can define this mapping:&lt;/p&gt;  &lt;p align="justify"&gt;&amp;lt;Framework:ViewSelector x:Key=&amp;quot;ApplicationViewSelector&amp;quot;&amp;gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Framework:ViewBinding ViewModelType=&amp;quot;INameU.ViewModels.NameListViewModel&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ViewUri=&amp;quot;/Views/NameListView.xaml&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Framework:ViewBinding ViewModelType=&amp;quot;INameU.ViewModels.NameDetailViewModel&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ViewUri=&amp;quot;/Views/NameDetailView.xaml&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;lt;/Framework:ViewSelector&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;where Framework is mapped as:&lt;/p&gt;  &lt;p align="justify"&gt;xmlns:Framework=&amp;quot;clr-namespace:MixModes.Phone.Synergy.Framework;assembly=MixModes.Phone.Synergy&amp;quot;&lt;/p&gt;  &lt;p align="justify"&gt;Once you have done this, you can call the Navigate method from your ViewModel instance to navigate to the mapped view and data binding to it at the same time, without using any url(s) !&lt;/p&gt;  &lt;h3 align="justify"&gt;DockPanel and WrapPanel Controls&lt;/h3&gt;  &lt;p align="justify"&gt;I have ported both DockPanel as well as WrapPanel from Silverlight Toolkit for Windows Phone 7 so you do not have to reference the toolkit if you are not using any additional functionality other than these panels.&lt;/p&gt;  &lt;h3 align="justify"&gt;EventToCommand TriggerAction&lt;/h3&gt;  &lt;p align="justify"&gt;A common pain point is the absence of Command and CommandParameter properties on controls such as Button and ListBoxItem. To fill this gap EventToCommand trigger action can be used to map a RoutedEvent to an ICommand instance along with a CommandParameter instance. To bind the RoutedCommand to EventToCommand trigger you need to add the trigger to the associated framework element:&lt;/p&gt;  &lt;p align="justify"&gt;&amp;lt;Button Content=&amp;quot;Click Me&amp;quot;&amp;gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Custom:Interaction.Triggers&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Custom:EventTrigger EventName=&amp;quot;Click&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Triggers:EventToCommand Command=&amp;quot;{Binding Path=DataContext.ShowDetailsCommand, ElementName=Page}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PassEventArgsToCommand=&amp;quot;True&amp;quot;/&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Custom:EventTrigger&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Custom:Interaction.Triggers&amp;gt;    &lt;br /&gt;&amp;lt;/Button&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;PassEventArgsToCommand property when set to true, passes the RoutedEventArgs as CommandParameter to the associated ICommand’s Execute method.&lt;/p&gt;  &lt;h3 align="justify"&gt;ScrollLoadBehavior&lt;/h3&gt;  &lt;p align="justify"&gt;ScrollLoadBehavior allows asynchronous loading of data when user scrolls a scroll viewer vertically to the bottom. ScrollLoadBehavior has an associated ICommand and CommandParameter that are executed anytime scroll viewer reaches its bottommost point. Loading is detected via ICommand’s CanExecute method. For example:&lt;/p&gt;  &lt;p align="justify"&gt;&amp;lt;ListBox DataContext=&amp;quot;{Binding}&amp;quot;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ItemsSource=&amp;quot;{Binding Path=Names}&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Custom:Interaction.Behaviors&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Behavior:ScrollLoadBehavior Command=&amp;quot;{Binding Path=LoadNamesCommand}&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Custom:Interaction.Behaviors&amp;gt;    &lt;br /&gt;&amp;lt;/ListBox&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;Notice the explicit DataContext=”{Binding}” in the ListBox. This is necessary as without explicit parent data binding, ItemsSource sets the DataContext to its value thereby failing the binding for ScrollLoadBehavior.&lt;/p&gt;  &lt;h3 align="justify"&gt;Out Of The Box Converters&lt;/h3&gt;  &lt;p align="justify"&gt;Many frequently used out of the box converters have been provided in the toolkit:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;EnumMatchConverter – Matches a value of enum member with a constant value and returns boolean indicating the match. For example, if you want to enable a control when the state is StateEnum.IsError, you can do the following:       &lt;br /&gt;Enabled=&amp;quot;{Binding Path=State, Converter={StaticResource EnumConverter}, ConverterParameter=IsError}&amp;quot;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;NotConverter – Inverts the value of a boolean expression.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;VisibilityConverter – Based on a boolean value, shows (if value is true) or collapses (if value is false) visibility of a control&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;PipeConverter – Pipes a value through multiple converters to compute the end value of the binding expression. For example if you want to match a value to enumeration member “Loading” and then determine the visibility of a control you could declare a pipe converter as follows:       &lt;br /&gt;        &lt;br /&gt;&amp;lt;conv:PipeConverter x:Key=&amp;quot;LoadingMessageVisibilityConverter&amp;quot;&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;conv:EnumMatchConverter /&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;conv:VisibilityConverter /&amp;gt;        &lt;br /&gt;&amp;lt;/conv:PipeConverter&amp;gt;        &lt;br /&gt;        &lt;br /&gt;The values are piped from top to bottom, hence first EnumMatchConverter is invoked and then VisibilityConverter. To use it simply refer to the PipeConverter as follows:        &lt;br /&gt;        &lt;br /&gt;Visibility=&amp;quot;{Binding Path=State, Converter={StaticResource LoadingMessageVisibilityConverter}, ConverterParameter=Loading}&amp;quot;        &lt;br /&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;ThemeBasedResourceConverter – This converter returns resources based on the theme of Windows 7 Phone (either dark or light). To use this converter one needs to point to both theme resources via LightThemeResource and DarkThemeResource properties. For example if your application has navigation button images for both themes as NavigationLight.png and NavigationDark.png, you could use ThemeBasedResourceConverter to set the appropriate image as the background of a button as follows:&lt;/div&gt;      &lt;p&gt;&amp;lt;phone:PhoneApplicationPage.Resources&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:ThemeBasedResourceConverter x:Key=&amp;quot;ThemeBasedResourceConverter&amp;quot;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LightThemeResource=&amp;quot;../Resources/NavigationLight.png&amp;quot;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DarkThemeResource=&amp;quot;../Resources/NavigationDark.png&amp;quot; /&amp;gt;        &lt;br /&gt;&amp;lt;/phone:PhoneApplicationPage.Resources&amp;gt;&lt;/p&gt;      &lt;p&gt;And then refer to the above ThemeBasedResourceConverter in the button:       &lt;br /&gt;        &lt;br /&gt;&amp;lt;Button&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Stretch=&amp;quot;None&amp;quot;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Source=&amp;quot;{Binding Path=., RelativeSource={RelativeSource Self}, Converter={StaticResource ThemeBasedResourceConverter}}&amp;quot;&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Image&amp;gt;        &lt;br /&gt;&amp;lt;/Button&amp;gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So that’s all in v1 folks. I will be happy to receive any feedback you may have and will continuously develop Synergy toolkit to make your development easier whether you code in WPF, WP7 or Silverlight !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-1141419670348940762?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/1141419670348940762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=1141419670348940762' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/1141419670348940762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/1141419670348940762'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2011/01/mixmodes-synergy-toolkit-for-windows.html' title='MixModes Synergy Toolkit for Windows Phone 7'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-7229275817386880985</id><published>2011-01-01T21:31:00.001-08:00</published><updated>2011-01-01T21:33:01.433-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='BasePattern'/><category scheme='http://www.blogger.com/atom/ns#' term='Spy++'/><category scheme='http://www.blogger.com/atom/ns#' term='Active Accessibility'/><category scheme='http://www.blogger.com/atom/ns#' term='InvokePattern'/><category scheme='http://www.blogger.com/atom/ns#' term='AutomationPeer'/><category scheme='http://www.blogger.com/atom/ns#' term='Calculator Automation'/><category scheme='http://www.blogger.com/atom/ns#' term='TreeWalker'/><category scheme='http://www.blogger.com/atom/ns#' term='Attached properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Expression Trees'/><category scheme='http://www.blogger.com/atom/ns#' term='PatternInterface'/><category scheme='http://www.blogger.com/atom/ns#' term='UI Automation'/><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><category scheme='http://www.blogger.com/atom/ns#' term='Control Patterns'/><category scheme='http://www.blogger.com/atom/ns#' term='ExpandCollapsePattern'/><category scheme='http://www.blogger.com/atom/ns#' term='Software Testing'/><category scheme='http://www.blogger.com/atom/ns#' term='CodeProject'/><category scheme='http://www.blogger.com/atom/ns#' term='Accessibility'/><category scheme='http://www.blogger.com/atom/ns#' term='AutomationElement'/><category scheme='http://www.blogger.com/atom/ns#' term='Automated UI Testing'/><title type='text'>Automate your UI using Microsoft automation framework</title><content type='html'>&lt;p align="justify"&gt;UI automation is a programmatic interface to the user interface of your application to external applications that may be interested in programmatic communication with your UI. In fact UI automation is the prime facilitator for accessibility features in Windows where external applications such as screen readers that have no clue about your application, can still interact with your application easily.&lt;/p&gt;  &lt;p align="justify"&gt;I was acquainted with UI automation during my tenure at Microsoft in 2005 when I started working as software developer in test within Visual Studio Team Architects team on a project called Whitehorse. For those who need some background, Whitehorse consisted of SOA diagrams within Visual Studio (you can learn more about this project in the MSDN magazine &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163947.aspx" target="_blank"&gt;here&lt;/a&gt;). Testing of visual designers in the product test team was done entirely using an internal UI test automation framework built on top of Microsoft Active Accessibility framework. &lt;/p&gt;  &lt;p align="justify"&gt;The UI automation framework is relatively new to Windows platform and successor to Windows Active Accessibility. The framework provides a unified way to discover UI controls in an application built using any of the following desktop technologies: Win32, Windows Forms or WPF.&lt;/p&gt;  &lt;p align="justify"&gt;UI automation has several benefits when used in applications:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Accessibility features – UI automation provides accessibility support in your application. Accessibility support becomes even more important when there are matter of legal compliance in the domain your application is used in (e.g. Government regulations).&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Automated UI testing – UI automation can automate testing for application UI saving time and costs associated with manual and regression testing. Moreover given a set of use cases, UI automation can be used to verify application behavior via scenario tests.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Custom controls – If you are authoring custom controls, UI automation support enables end clients of your control to automate your control in their application UI.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;&lt;font size="3"&gt;How does UI automation work?&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;UI automation provides a common protocol for exchanging information between your application and an external entity such as screen reader or automated UI tests. UI automation provides an API using which an external application can discover controls, navigate the visual tree, access the state of the controls and perform control specific actions.&lt;/p&gt;  &lt;p align="justify"&gt;In WPF, automation object model is provided via System.Windows.Automation.AutomationElement instance associated with a UIElement (said to be “automation peer” of the control). If you are authoring a custom control, you may want to implement one or more interfaces defined in the UIAutomationProvider.dll under the System.Windows.Automation.Provider namespace to support UI automation.&lt;/p&gt;  &lt;p align="justify"&gt;To support UI automation, a control author needs to implement an abstract class AutomationPeer from UIElement class’ virtual method OnCreateAutomationPeer. AutomationPeer&amp;#160; is then used at runtime to extract AutomationElement for the UIElement. It is important to note that the standard controls in WPF have standard implementation of AutomationPeer associated with the controls out of the box. In authoring a derivative of AutomationPeer you may want to subclass a standard implementation rather than deriving directly from AutomationPeer and authoring a class from scratch.&lt;/p&gt;  &lt;p align="justify"&gt;Following image shows out of the box derivatives of AutomationPeer:&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh3.ggpht.com/_LOoKjxVTcbc/TSAMlsIszKI/AAAAAAAAHDc/f3_unENta8M/s1600-h/image%5B30%5D.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://lh4.ggpht.com/_LOoKjxVTcbc/TSAMl4LochI/AAAAAAAAHDg/IZmVf1_Bvqs/image_thumb%5B18%5D.png?imgmax=800" width="325" height="433" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Each AutomationPeer must implement one or more “standard control patterns” to expose capabilities that can be used by automation clients such as screen readers. A control may expose one or more control patterns defined by the members of PatternIntern enumeration:&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh6.ggpht.com/_LOoKjxVTcbc/TSAMmFC1Q8I/AAAAAAAAHDk/ZlakNcQchcs/s1600-h/image%5B29%5D.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://lh3.ggpht.com/_LOoKjxVTcbc/TSAMmYNlcsI/AAAAAAAAHDo/nAFdKBeFgjw/image_thumb%5B17%5D.png?imgmax=800" width="148" height="378" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;A control can be queried for a specific PatternInferface via AutomationPeer’s GetPattern method that takes PatternInterface member as a parameter and returns the supported pattern – a derivative of BasePattern or null if the specified PatternInterface value does not correspond to a supported pattern.&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TSAMmsgRg4I/AAAAAAAAHEk/DXDhBTR3XIE/s1600-h/image%5B42%5D.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://lh5.ggpht.com/_LOoKjxVTcbc/TSAMnQ-DVzI/AAAAAAAAHEo/0arQtTD0xuE/image_thumb%5B26%5D.png?imgmax=800" width="800" height="176" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;BasePattern has several out of the box derivatives that target standard control patterns:&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TSAMng9x1WI/AAAAAAAAHD0/J52pFhIw1HA/s1600-h/image%5B26%5D.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://lh5.ggpht.com/_LOoKjxVTcbc/TSAMn_vJcFI/AAAAAAAAHD4/OJa1xMlGPNw/image_thumb%5B14%5D.png?imgmax=800" width="233" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;For example Button, Hyperlink and MenuItem controls support InvokePattern and can therefore indicate to the automation clients that control is capable of invoking a command. Similarly an expander control supports ExpandCollapsePattern to indicate that control is capable of expanding or collapsing content within it.&lt;/p&gt;  &lt;p align="justify"&gt;Control patterns are strictly limited and custom control patterns are not supported. The reason is that automation clients must work on a standardized protocol and cannot interpret custom patterns to figure out the functionality of the controls.&lt;/p&gt;  &lt;p align="justify"&gt;Since UI automation is optional in WPF, you may tag on automation properties on a control via attached properties specified in the AutomationProperties static class:&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh5.ggpht.com/_LOoKjxVTcbc/TSAMoK8QWSI/AAAAAAAAHD8/eafhiRXKhpc/s1600-h/image%5B25%5D.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://lh6.ggpht.com/_LOoKjxVTcbc/TSAMoQ8A-II/AAAAAAAAHEA/6u2IkRr2AOs/image_thumb%5B13%5D.png?imgmax=800" width="322" height="224" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;For example if we want to specify automation id on a text box we could specify it as following in XAML:&lt;/p&gt;  &lt;p align="justify"&gt;&amp;lt;TextBox Text=”{Binding Telephone}” AutomationProperties.Id=”ID_TXT_TELEPHONE”/&amp;gt;&lt;/p&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;Navigating the automation tree in WPF&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;Similar to visual tree navigation, one can navigate UI automation tree in WPF using the AutomationElement instance. However there is an important distinction – unlike the visual tree, an automation tree is not constructed upfront and is only constructed during automation tree navigation. This is so because unlike visual tree, UI automation is optional in applications. There are more than one way to navigate the automation tree depending on the view of automation tree you would want:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Raw view – Raw view refers to non-filtered complete automation tree view. Using TreeWalker class’ RawViewWalker property raw view can be navigated.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Control view – A control view is a subset of raw view that only contains AutomationElements that correspond to controls (or in other words have their AutomationElement.IsControlElementProperty property set). Using TreeWalker class’ ControlViewWalker property control view can be navigated.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Content view – A content view is a subset of control view that only contains AutomationElements that correspond to elements that represent information in terms of content to the end user(or in other words have their AutomationElement.IsContentElementProperty property set). Using TreeWalker class’ ContentViewWalker property content view can be navigated.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Custom view – Using a AutomationElement and a condition (which can be one of PropertyCondition, AndCondition, OrCondition or NotCondition) one can navigate automation tree in a custom manner. To navigate a custom view a call to the FirstFind or FindAll methods of AutomationElement is made with a tree scope (TreeScope enumeration specifying the levels in terms of Element, Children, Descendants, Subtree, Parent and Ancestors or any combination of these flags) and a condition.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;The root of the automation tree is represented by static property AutomationElement.RootElement refers to the user’s desktop. One can either navigate a automation tree via RootElement or quite often more efficiently from the AutomationElement corresponding to the application window which can be obtained via AutomationElement.FromHandle method by passing in the handle to the application window.&lt;/p&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;A real world example – automating Windows calculator&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;As a real world example, let’s author test cases that uses UI automation to test Windows calculator. The aim of the tests is to test the following aspects of calculator:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Data entry verification – Validates that a number being typed appears correctly in the calculator&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Editing options – Validates that copy and paste works as expected in the calculator&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Calculation validation – Validates given an expression tree, calculator calculates the expression correctly.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;You may download the completed example from below:&lt;/p&gt; &lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-a521a90cb40d14ff.office.live.com/embedicon.aspx/BloggerContent/CalculatorTests.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;font size="3"&gt;Calculator class&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;We will start the example by modeling Calculator class which will be our interface to Windows calculator. The calculator class shall fire up an instance of Windows calculator upon construction and shall provide methods to manipulate the calculator. Also this class shall implement IDisposable interface and shall dispose the calculator process upon test conclusion. Clean calculator instance for every test ensures no d&lt;/p&gt;  &lt;p align="justify"&gt;Following is the constructor of Calculator class:&lt;/p&gt;  &lt;p&gt;public Calculator()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; _calculatorProcess = Process.Start(&amp;quot;Calc.exe&amp;quot;);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; int ct = 0;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; do     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _calculatorAutomationElement = AutomationElement.RootElement.FindFirst(TreeScope.Children,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyCondition(AutomationElement.NameProperty, &amp;quot;Calculator&amp;quot;));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ++ct;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Thread.Sleep(100);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; while (_calculatorAutomationElement == null &amp;amp;&amp;amp; ct &amp;lt; 50);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; if (_calculatorAutomationElement == null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new InvalidOperationException(&amp;quot;Calculator must be running&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; _resultTextBoxAutomationElement = _calculatorAutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, &amp;quot;150&amp;quot;));&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; if (_resultTextBoxAutomationElement == null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new InvalidOperationException(&amp;quot;Could not find result box&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; GetInvokePattern(GetFunctionButton(Functions.Clear)).Invoke();    &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;The code fires up calculator process and waits for automation element to become available. Then it proceeds to discovering and initializing automation elements that will be used to interact with the calculator. For example to obtain access to calculator result text box we do a lookup of automation id of 150 within the main calculator automation element. Automation Ids of elements were obtained using Spy++ utility that ships with Visual Studio by following the steps below:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Fire up a calculator instance and then fire up Spy++. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Type any number in calculator (I typed 1234) to identify it within Spy++. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Press Ctrl + F3 in Spy++ and from the search window drag the cross bow over to the calculator instance. This will highlight the calculator process in Spy ++.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Find the window instance corresponding to the pressed number and click to select it.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Right click on the selected window and select Properties menu item to fire up the properties window&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Look up the control Id in the Property Inspector window. This is the automation id for the control in Hex. Convert it into decimal before using it in code. In my case a hex value of 96 corresponds to 150 in decimal. This is how I got 150 !&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TSAMonWJHOI/AAAAAAAAHEE/xFz2DYTO0vc/s1600-h/image%5B40%5D.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://lh3.ggpht.com/_LOoKjxVTcbc/TSAMosv4FBI/AAAAAAAAHEI/1KA7CZyEYGM/image_thumb%5B24%5D.png?imgmax=800" width="270" height="129" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh6.ggpht.com/_LOoKjxVTcbc/TSAMpEYl-cI/AAAAAAAAHEM/rNXxc__3SCo/s1600-h/image%5B35%5D.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://lh6.ggpht.com/_LOoKjxVTcbc/TSAMpoyDQ6I/AAAAAAAAHEQ/SfeXcZP0axA/image_thumb%5B21%5D.png?imgmax=800" width="396" height="298" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Dispose method simply terminate the process:&lt;/p&gt;  &lt;p&gt;public void Dispose()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; _calculatorProcess.CloseMainWindow();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; _calculatorProcess.Dispose();     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;To obtain InvokePattern to invoke buttons we use a utility method GetInvokePattern for a specified AutomationElement:&lt;/p&gt;  &lt;p&gt;public InvokePattern GetInvokePattern(AutomationElement element)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;AutomationElement for a function button can be retrieved via GetFunctionButton method that takes in string for the function (e.g. “Clear”) as its input:&lt;/p&gt;  &lt;p&gt;public AutomationElement GetFunctionButton(string functionName)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; AutomationElement functionButton = _calculatorAutomationElement.FindFirst(TreeScope.Descendants,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; newPropertyCondition(AutomationElement.NameProperty, functionName));&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; if (functionButton == null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new InvalidOperationException(&amp;quot;No function button found with name: &amp;quot; + functionName);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; return functionButton;    &lt;br /&gt;}     &lt;br /&gt;    &lt;br /&gt;All the function names are defined within the Functions static class:&lt;/p&gt;  &lt;p&gt;public class Functions    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // Functions     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string MemoryClear = &amp;quot;Memory clear&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Backspace = &amp;quot;Backspace&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string MemoryRecall = &amp;quot;Memory recall&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string ClearEntry = &amp;quot;Clear entry&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string MemoryStore = &amp;quot;Memory store&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Clear = &amp;quot;Clear&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string DecimalSeparator = &amp;quot;Decimal separator&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string MemoryAdd = &amp;quot;Memory add&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string MemoryRemove = &amp;quot;Memory subtract&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Equals = &amp;quot;Equals&amp;quot;;     &lt;br /&gt;}     &lt;br /&gt;    &lt;br /&gt;Similarly we query for a digit button using GetDigitButton method that takes digit as an input and returns the associated AutomationElement:&lt;/p&gt;  &lt;p&gt;public AutomationElement GetDigitButton(int number)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if ((number &amp;lt; 0) || (number &amp;gt; 9))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new InvalidOperationException(&amp;quot;mumber must be a digit 0-9&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; AutomationElement buttonElement = _calculatorAutomationElement.FindFirst(TreeScope.Descendants,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyCondition(AutomationElement.NameProperty, number.ToString()));&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; if (buttonElement == null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new InvalidOperationException(&amp;quot;Could not find button corresponding to digit&amp;quot; + number);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; return buttonElement;    &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;One thing to note is the use of AutomationElement.NameProperty in querying for the element. This property cannot be seen via Spy++ and I had to open the inspect the object in debugger to find it out (I used AutomationId to load an element and queried it in the debugger to find the name property).    &lt;br /&gt;    &lt;br /&gt;The result of calculator can be retrieved using Result property. The setter of this property parses the character string from left to right, locates the AutomationElement for the button on the calculator corresponding to the character and then invokes it using InvokePattern’s Invoke method. This is really mimicking user typing numbers in the calculator.&lt;/p&gt;  &lt;p&gt;public object Result    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return _resultTextBoxAutomationElement.GetCurrentPropertyValue(AutomationElement.NameProperty);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; set     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string stringRep = value.ToString();&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; for (int index = 0; index &amp;lt; stringRep.Length; index++)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int leftDigit = int.Parse(stringRep[index].ToString());&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetInvokePattern(GetDigitButton(leftDigit)).Invoke();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;The Evaluate, Clear and InvokeFunction methods simply evaluates (mimicking pressing of = button), clears (mimicking pressing of C button) and invokes a function respectively:&lt;/p&gt;  &lt;p&gt;public void Evaluate()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; InvokeFunction(Functions.Equals);     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;public void Clear()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; InvokeFunction(Functions.Clear);     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;public void InvokeFunction(string functionName)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; GetInvokePattern(GetFunctionButton(functionName)).Invoke();     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;FindMenu method locates the specified calculator menu and returns its ExpandCollapsePattern:&lt;/p&gt;  &lt;p&gt;private ExpandCollapsePattern FindMenu(CalculatorMenu menu)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; AutomationElement menuElement = _calculatorAutomationElement.FindFirst(TreeScope.Descendants,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyCondition(AutomationElement.NameProperty, menu.ToString()));     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ExpandCollapsePattern expPattern = menuElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ExpandCollapsePattern;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return expPattern;     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;OpenMenu and CloseMenu uses FindMenu to obtain ExpandCollapsePattern for menus and then expand and collapse menus respectively. ExecuteByMenuName looks for a menu item within expanded menu and invokes the command using the InvokePattern of the menu.&lt;/p&gt;  &lt;p&gt;public void OpenMenu(CalculatorMenu menu)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ExpandCollapsePattern expPattern = FindMenu(menu);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expPattern.Expand();     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;public void CloseMenu(CalculatorMenu menu)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ExpandCollapsePattern expPattern = FindMenu(menu);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expPattern.Collapse();     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;public void ExecuteMenuByName(string menuName)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; AutomationElement menuElement = _calculatorAutomationElement.FindFirst(TreeScope.Descendants,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyCondition(AutomationElement.NameProperty, menuName));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (menuElement == null)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; InvokePattern invokePattern = menuElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (invokePattern != null)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; invokePattern.Invoke();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;Now that we have exposed functionality of calculator that we would interact with, we can proceed and model expression tree so we can evaluate expressions in the calculator. For the purpose of testing expression evaluation we need two modes of expression computation: expression evaluation through calculator UI (calculated expression) and evaluation through code (expected evaluation). If calculated expression equals expected expression we can assert that calculator computes expression in the correct manner. This evaluation option is captured via EvaluateOption enumeration:&lt;/p&gt;  &lt;p&gt;internal enum EvaluateOption    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; UIEvaluate,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ActualEvaluate     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;At the end level, we need to model the operands that have sub-expressions to evaluate. Operands are modeled using IOperand interface:&lt;/p&gt;  &lt;p&gt;internal interface IOperand    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int Evaluate(EvaluateOption option, Calculator calculator);     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;At the fundamental level, an operator is an operand:&lt;/p&gt;  &lt;p&gt;internal abstract class Operator : IOperand    &lt;br /&gt;{&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; internal Operator(string automationName)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AutomationName = automationName;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public string AutomationName { private set; get; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public abstract int Evaluate(EvaluateOption option, Calculator calculator);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; protected virtual void InvokeOperator(Calculator calculator)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calculator.InvokeFunction(AutomationName);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;Automation name refers to constants within Operators class which correspond to function names in calculator (i.e.&amp;#160; AutomationElement.NameProperty values):&lt;/p&gt;  &lt;p&gt;internal class Operators    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Negate = &amp;quot;Negate&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Divide = &amp;quot;Divide&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Multiply = &amp;quot;Multiply&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Subtract = &amp;quot;Subtract&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Add = &amp;quot;Add&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Sqrt = &amp;quot;Square root&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Percentage = &amp;quot;Percentage&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public const string Reciprocal = &amp;quot;Reciprocal&amp;quot;;     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;A binary operator is represented using BinaryOperator abstract class:&lt;/p&gt;  &lt;p&gt;internal abstract class BinaryOperator : Operator    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public BinaryOperator(string automationName)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : base(automationName)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public IOperand Left { get; set; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public IOperand Right { get; set; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public override int Evaluate(EvaluateOption option, Calculator calculator)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; VerifyEvaluationState();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int result = 0;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; switch (option)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EvaluateOption.UIEvaluate:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calculator.Clear();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int leftValue = Left.Evaluate(option, calculator);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calculator.Clear();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int rightValue = Right.Evaluate(option, calculator);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calculator.Clear();&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calculator.Result = leftValue;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; InvokeOperator(calculator);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calculator.Result = rightValue;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calculator.Evaluate();&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; result = int.Parse(calculator.Result.ToString());&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EvaluateOption.ActualEvaluate:    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; result = Evaluate(Left.Evaluate(option, calculator), Right.Evaluate(option, calculator));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return result;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; protected void VerifyEvaluationState()    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if ((Left == null) || (Right == null))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new InvalidOperationException();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; protected abstract int Evaluate(int left, int right);    &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;As can be seen if EvaluateOption.UIEvaluate is used within Evaluate function then UI automation is used to mimic the user’s input in calculator; otherwise evaluation of expression is done in code. The other Evaluate overload is implemented in derivative classes such as AddOperator, SubtractOperator, MultiplyOperator and DivideOperator. AddOperator class is as follows (rest of the operators are very similar differing only in actual computation and automation name in constructor):&lt;/p&gt;  &lt;p&gt;internal class AddOperator : BinaryOperator    &lt;br /&gt;{&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public AddOperator()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : base(Operators.Add)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; protected override int Evaluate(int left, int right)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return left + right;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;NumberOperator is just a number constant in expression tree:&lt;/p&gt;  &lt;p&gt;internal class NumberOperator : Operator    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public NumberOperator(int number)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : base (null)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _number = number;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public override int Evaluate(EvaluateOption option, Calculator calculator)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return _number;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private readonly int _number;    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;ExpressionTree class creates an expression tree from a XML stream via CreateTree method:&lt;/p&gt;  &lt;p&gt;internal static class ExpressionTree    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; internal static IOperand CreateTree(Stream stream)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; XDocument doc = XDocument.Load(stream);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return CreateOperend(doc.Root);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private static IOperand CreateOperend(XElement operandElement)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; XAttribute type = operandElement.Attribute(&amp;quot;Type&amp;quot;);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IOperand operand = null;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; switch (type.Value)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case &amp;quot;NumberOperator&amp;quot;:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; operand = new NumberOperator(int.Parse(operandElement.Attribute(&amp;quot;Value&amp;quot;).Value));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; default:    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string qualifyingName = &amp;quot;CalculatorTests.&amp;quot; + type.Value;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; operand = Activator.CreateInstance(Type.GetType(qualifyingName)) as IOperand;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; List&amp;lt;XNode&amp;gt; childNodes = new List&amp;lt;XNode&amp;gt;(operandElement.Nodes());&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (operand is BinaryOperator)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; BinaryOperator binaryOperator = operand as BinaryOperator;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; binaryOperator.Left = CreateOperend(childNodes[0] as XElement);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; binaryOperator.Right = CreateOperend(childNodes[1] as XElement);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else if (operand is UnaryOperator)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; UnaryOperator unaryOperator = operand as UnaryOperator;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unaryOperator.Operand = CreateOperend(childNodes[0] as XElement);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return operand;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;CreateTree calls CreateOperend method that parses the XElement’s Type attribute to determine type of operand and depending on whether type is NumberOperator (in which case it looks for Value attribute) or otherwise (unary or binary operand in which case it looks for child Operand xml elements), it creates and returns an IOperand recursively (if needed). Finally the root operand is returned. As an example the expression (6 - 1) + (7 * 9) is represented using the xml:&lt;/p&gt;  &lt;p&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;    &lt;br /&gt;&amp;lt;Operand Type=&amp;quot;AddOperator&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;Operand Type=&amp;quot;SubtractOperator&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Operand Type=&amp;quot;NumberOperator&amp;quot; Value=&amp;quot;6&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Operand Type=&amp;quot;NumberOperator&amp;quot; Value=&amp;quot;1&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;/Operand&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;Operand Type=&amp;quot;MultiplyOperator&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Operand Type=&amp;quot;NumberOperator&amp;quot; Value=&amp;quot;7&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Operand Type=&amp;quot;NumberOperator&amp;quot; Value=&amp;quot;9&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;/Operand&amp;gt;     &lt;br /&gt;&amp;lt;/Operand&amp;gt;     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;Now that we have successfully created the infrastructure for interacting with the calculator and evaluating the expression tree, we can start authoring test cases:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Verify data entry of a random number in calculator and verify result shows up correctly in the UI      &lt;br /&gt;      &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void TypeRandomNumber()       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; using (Calculator calc = new Calculator())       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int number = new Random().Next(100, 10000);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string stringRep = number.ToString();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.Result = stringRep;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(stringRep, calc.Result);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Verify cut and paste functionality:      &lt;br /&gt;      &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void VerifyCopyPaste()       &lt;br /&gt;{&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; using (Calculator calc = new Calculator())       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string stringRep = new Random().Next(100, 10000).ToString();&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.Result = stringRep;       &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.OpenMenu(Calculator.CalculatorMenu.Edit);        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.ExecuteMenuByName(&amp;quot;Copy&amp;quot;);&lt;/p&gt;      &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.Clear();&lt;/p&gt;      &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.OpenMenu(Calculator.CalculatorMenu.Edit);        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.ExecuteMenuByName(&amp;quot;Paste&amp;quot;);&lt;/p&gt;      &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(stringRep, calc.Result);        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }         &lt;br /&gt;}&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;Verification of expression tree computation from embedded xml resource files:      &lt;br /&gt;      &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void VerifyExpressionTrees()       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string[] files = new[]       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;CalculatorTests.Resources.SimpleNumberOperator.xml&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;CalculatorTests.Resources.SimpleAdditionOperator.xml&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;CalculatorTests.Resources.MixedOperators.xml&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; };       &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; using (Calculator calc = new Calculator())        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (string file in files)         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; calc.Clear();         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IOperand expression = LoadExpressionTreeFromFile(file);         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expression.Evaluate(EvaluateOption.ActualEvaluate, calc), expression.Evaluate(EvaluateOption.UIEvaluate, calc));         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }         &lt;br /&gt;}         &lt;br /&gt;        &lt;br /&gt;private IOperand LoadExpressionTreeFromFile(string resourceFileName)         &lt;br /&gt;{&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return ExpressionTree.CreateTree(this.GetType().Assembly.GetManifestResourceStream(resourceFileName));         &lt;br /&gt;}&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;You may run the tests using Visual Studio test manager and will see calculator instances popping up and controls being manipulated as per the test cases followed by termination of calculator process (remember the IDisposable implementation in Calculator class that does the teardown).&lt;/p&gt;  &lt;p align="justify"&gt;So that’s it, you have just seen an automation client in action! Stay tuned for my next blog where I will demonstrate how to implement automation support during the development of custom controls.&lt;/p&gt;  &lt;p align="justify"&gt;You may also want to look at project White on &lt;a href="http://white.codeplex.com/" target="_blank"&gt;codeplex&lt;/a&gt; which is based on UI automation framework and aims to simplify UI automation programming model.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-7229275817386880985?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/7229275817386880985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=7229275817386880985' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/7229275817386880985'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/7229275817386880985'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2011/01/automate-your-ui-using-microsoft.html' title='Automate your UI using Microsoft automation framework'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_LOoKjxVTcbc/TSAMl4LochI/AAAAAAAAHDg/IZmVf1_Bvqs/s72-c/image_thumb%5B18%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-4186265242180610464</id><published>2010-12-27T18:39:00.001-08:00</published><updated>2010-12-27T18:47:19.756-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF Behaviors'/><category scheme='http://www.blogger.com/atom/ns#' term='Attached properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Icon'/><category scheme='http://www.blogger.com/atom/ns#' term='Dependency Properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><category scheme='http://www.blogger.com/atom/ns#' term='Data Binding'/><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes Synergy 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='user control'/><category scheme='http://www.blogger.com/atom/ns#' term='CodeProject'/><category scheme='http://www.blogger.com/atom/ns#' term='Custom Windows'/><title type='text'>Create custom windows in WPF with ease</title><content type='html'>&lt;p align="justify"&gt;One of the features I wanted to add to Synergy toolkit was the ability to quickly create custom theme windows with all the features of a standard windows. In this article I am demonstrating how to create a custom window theme visually using declarative XAML and apply it to windows in your applications. &lt;/p&gt;  &lt;p align="justify"&gt;You can download Synergy SDK with full source code &lt;a href="http://www.codeproject.com/KB/WPF/WPFDockingToolkit/Synergy.zip" target="_blank"&gt;here&lt;/a&gt;.     &lt;br /&gt;You may also want to see my window docking solution in Synergy &lt;a href="http://www.codeproject.com/KB/WPF/WPFDockingToolkit.aspx" target="_blank"&gt;here&lt;/a&gt;.    &lt;br /&gt;I will be posting updates on Synergy SDK on my twitter account: MixModes    &lt;br /&gt;    &lt;br /&gt;The sample application Synergy uses main window as the custom window whose theme is defined within Windows.xaml resource dictionary within MixModes.Synergy.Themes project.&lt;/p&gt;  &lt;h3&gt;&lt;font size="3"&gt;Declarative is the key&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;As we all know XAML is declarative and simple and so there is no reason why traditional approach of writing code for windows and controls should apply. One must be able to simply create a visual and stick it in a control template to get things working. That was exactly my motivation when I started out developing look-less window functionality in Synergy.&lt;/p&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;Declare a template&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;The first thing you may want to do in creating a custom window is to actually create a visual template. The easiest way to create this template is to create a user control in Microsoft Blend and then define extension points in XAML that look-less control will liven up once the template is applied. Once the visual is ready all that needs to be done is a style creation for CustomWindow where the template can be pasted and then the temporary user control can be discarded.&lt;/p&gt;  &lt;p align="justify"&gt;Following extension points are supported for current implementation:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;PART_TITLEBAR (UIElement) - For displaying window title, dragging and maximize / restore operations&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;PART_MINIMIZE (Button) – Window minimize button&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;PART_MAXIMIZE_RESTORE (Button) – Maximize restore button&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;PART_CLOSE (Button) – Close button&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;PART_LEFT_BORDER (UIElement) – Left resizable border&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;PART_RIGHT_BORDER (UIElement) – Right resizable border&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;PART_TOP_BORDER (UIElement) – Top resizable border&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;PART_BOTTOM_BORDER (UIElement) – Bottom resizable border&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;One more thing to note is that while defining the window template, you must declare the ContentPresenter (which ultimately contains window content) within AdornerDecorator tag (which is the adorner layer for the window) as this is WPF requirement.&lt;/p&gt;  &lt;p align="justify"&gt;Here is the template I have created within Windows.xaml resource dictionary within MixModes.Synergy.Themes project:&lt;/p&gt;  &lt;p&gt;&amp;lt;ResourceDictionary xmlns=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/a&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; xmlns:x=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;"&gt;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/a&gt;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Style x:Key=&amp;quot;MainWindow&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; TargetType=&amp;quot;{x:Type Window}&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Foreground&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Value=&amp;quot;{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Template&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ControlTemplate TargetType=&amp;quot;{x:Type Window}&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Grid&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Border x:Name=&amp;quot;MainBorder&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; BorderBrush=&amp;quot;{DynamicResource MainWindowBorderBrush}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; BorderThickness=&amp;quot;1&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CornerRadius=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Background=&amp;quot;{DynamicResource MainWindowBackgroundBrush}&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DockPanel LastChildFill=&amp;quot;True&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle x:Name=&amp;quot;PART_LEFT_BORDER&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Width=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Cursor=&amp;quot;SizeWE&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;SolidColorBrush Color=&amp;quot;Transparent&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle x:Name=&amp;quot;PART_RIGHT_BORDER&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Cursor=&amp;quot;SizeWE&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Width=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Right&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;SolidColorBrush Color=&amp;quot;Transparent&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle x:Name=&amp;quot;PART_TOP_BORDER&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Cursor=&amp;quot;SizeNS&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Top&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Height=&amp;quot;2&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;SolidColorBrush Color=&amp;quot;Transparent&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle x:Name=&amp;quot;PART_BOTTOM_BORDER&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Cursor=&amp;quot;SizeNS&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Height=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Bottom&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;SolidColorBrush Color=&amp;quot;Transparent&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle.Fill&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Rectangle&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Border x:Name=&amp;quot;PART_TITLEBAR&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Margin=&amp;quot;2,0,2,2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Height=&amp;quot;40&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Top&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CornerRadius=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Background=&amp;quot;Transparent&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DockPanel LastChildFill=&amp;quot;False&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;TextBlock Margin=&amp;quot;8,0,0,4&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; VerticalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; FontStretch=&amp;quot;UltraExpanded&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Foreground=&amp;quot;Black&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; TextTrimming=&amp;quot;CharacterEllipsis&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; TextWrapping=&amp;quot;NoWrap&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Text=&amp;quot;{TemplateBinding Title}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; FontSize=&amp;quot;16&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Button x:Name=&amp;quot;PART_CLOSE&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Right&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Style=&amp;quot;{DynamicResource FlatButton}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; VerticalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Margin=&amp;quot;0,0,4,0&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Source=&amp;quot;/MixModes.Synergy.Resources;component/Resources/Close.png&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Stretch=&amp;quot;None&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Margin=&amp;quot;4&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Button&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Button x:Name=&amp;quot;PART_MAXIMIZE_RESTORE&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Right&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; HorizontalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; VerticalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Style=&amp;quot;{DynamicResource FlatButton}&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image x:Name=&amp;quot;MaximizeRestoreImage&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Source=&amp;quot;/MixModes.Synergy.Resources;component/Resources/Restore.png&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Stretch=&amp;quot;None&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Margin=&amp;quot;4&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Button&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Button x:Name=&amp;quot;PART_MINIMIZE&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; HorizontalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Style=&amp;quot;{DynamicResource FlatButton}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; VerticalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Right&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Margin=&amp;quot;4&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Source=&amp;quot;/MixModes.Synergy.Resources;component/Resources/Minimize.png&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Stretch=&amp;quot;None&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Button&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/DockPanel&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Border&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;!-- Title bar separator--&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Border Height=&amp;quot;1&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPanel.Dock=&amp;quot;Top&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Background=&amp;quot;{DynamicResource MainWindowTitleBarSeparator}&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;!-- Actual Window Content --&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;AdornerDecorator DockPanel.Dock=&amp;quot;Bottom&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ContentPresenter /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/AdornerDecorator&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/DockPanel&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Border&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Grid&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ControlTemplate.Triggers&amp;gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DataTrigger Binding=&amp;quot;{Binding RelativeSource={RelativeSource Self}, Path=Maximized}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Value=&amp;quot;False&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter TargetName=&amp;quot;MaximizeRestoreImage&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Property=&amp;quot;Source&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Value=&amp;quot;/MixModes.Synergy.Resources;component/Resources/Maximize.png&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/DataTrigger&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/ControlTemplate.Triggers&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/ControlTemplate&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Style&amp;gt;     &lt;br /&gt;&amp;lt;/ResourceDictionary&amp;gt;&lt;/p&gt;  &lt;p&gt;This is a pretty simple theme which creates a rounded rectangle window with 2 pixel wide resizers and custom window minimize, maximize and restore buttons. It also contains a template trigger that changes the image of maximize restore button if window is not maximized.&lt;/p&gt;  &lt;p&gt;The window created using this theme looks like the following:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LOoKjxVTcbc/TRlN6EEAw-I/AAAAAAAAHCA/ljJPWo8CAMU/s1600-h/image%5B7%5D.png"&gt;&lt;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="http://lh4.ggpht.com/_LOoKjxVTcbc/TRlN6iMUqJI/AAAAAAAAHCE/zUmQLelwx-8/image_thumb%5B3%5D.png?imgmax=800" width="389" height="339" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;Inherit from CustomWindow class&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;The final step is to inherit from CustomWindow class (which in turn inherits from Window class) instead of directly inheriting from Window class and refer to the style created in the previous step. This is again very simple:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Import visual framework namespace:       &lt;br /&gt;&lt;a title="xmlns:visualFx=&amp;quot;http://mixmodes.com/visualFx&amp;quot;" href="xmlns:visualFx=&amp;quot;http://mixmodes.com/visualFx&amp;quot;"&gt;xmlns:visualFx=&amp;quot;http://mixmodes.com/visualFx&amp;quot;&lt;/a&gt;        &lt;br /&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Inherit from CustomWindow class:       &lt;br /&gt;use “visualFx:CustomWindow” as your window tag in XAML        &lt;br /&gt;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Refer to the style created in previous step in your visualFx:CustomWindow tag:       &lt;br /&gt;Style=&amp;quot;{DynamicResource MainWindow}&amp;quot;&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;That’s all you have to do to get your custom window working !&lt;/p&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;How does it work?&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;If you crack open the CustomWindow class you will see that bulk of the work happens in the AttachToVisualTree method which is called from OnApplyTemplate (which in turn is called anytime template is applied to our custom window).   &lt;br /&gt;    &lt;br /&gt;AttachToVisualTree in turn calls AttachCloseButton, AttachMaximizeButton, AttachMaximizeRestoreButton, AttachTitleBar and AttachBorders methods, each of which queries for visual parts (the PART_… named parts we defined in the template) and attaches functionality via events.&lt;/p&gt;  &lt;p align="justify"&gt;So that’s it ! Creating custom windows using Synergy is really that simple !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-4186265242180610464?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/4186265242180610464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=4186265242180610464' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/4186265242180610464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/4186265242180610464'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2010/12/create-custom-windows-in-wpf-with-ease.html' title='Create custom windows in WPF with ease'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_LOoKjxVTcbc/TRlN6iMUqJI/AAAAAAAAHCE/zUmQLelwx-8/s72-c/image_thumb%5B3%5D.png?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-997336511222342604</id><published>2010-12-27T10:17:00.001-08:00</published><updated>2010-12-31T12:49:51.605-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF Behaviors'/><category scheme='http://www.blogger.com/atom/ns#' term='Attached properties'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF Handlers'/><category scheme='http://www.blogger.com/atom/ns#' term='Dependency Properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Behavior Driven Development'/><category scheme='http://www.blogger.com/atom/ns#' term='Design Patterns'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes Synergy 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='user control'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='CodeProject'/><category scheme='http://www.blogger.com/atom/ns#' term='Behavior Handler Pattern'/><title type='text'>Building a docking window management solution in WPF</title><content type='html'>&lt;p align="justify"&gt;Window docking is a familiar functionality in multi-windows applications. As a user interface developer this behavior has always charmed me and so I thought of developing the same functionality in my own WPF toolkit. I know there are many implementations of similar solutions out there, some even open source, but my aim was to take this personal project as a challenge and learning opportunity.&lt;/p&gt;  &lt;p align="justify"&gt;I should also mention that the docking solution I have implemented is part of a bigger WPF toolkit that I am building on an ongoing basis under my company &lt;a href="http://mixmodes.com" target="_blank"&gt;MixModes Inc&lt;/a&gt;, however I intend to keep it open source and royalty free project. To preview the full feature set of this library you can visit my blog &lt;a href="http://ashishkaila.blogspot.com/2010/12/introducing-mixmodes-synergy-2010.html" target="_blank"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p align="justify"&gt;Many existing implementations of window docking solutions have floating windows as separate windows managed under MDI parent window. However I have kept floating windows contained strictly within parent window as I intend to port this code to Silverlight soon.&lt;/p&gt;  &lt;p align="justify"&gt;You may download the source code here.&lt;/p&gt; &lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-a521a90cb40d14ff.office.live.com/embedicon.aspx/BloggerContent/Synergy.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/h3&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;Anatomy of Synergy Toolkit&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;MixModes Synergy toolkit consists of following top level projects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;MixModes.Synergy.Resources – Contains image and language resources&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;MixModes.Synergy.Themes – Defines default themes for user controls, custom windows, colors, brushes and text themes&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;MixModes.Synergy.Utilities – Common utilities&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;MixModes.Synergy.VisualFramework – Contains behaviors, adorners, commands, user controls, docking framework and other WPF specific functionality&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Synergy – Sample project highlighting features of the toolkit&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;Anatomy of a Dockable window&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;To understand window docking solution, it is necessary to understand the very primitive control that drives it all – the dockable window. A dockable window is a special window that in addition to content and title can be in following several states:&lt;/p&gt;  &lt;p&gt;1. Pinned state – Dockable window can be pinned to the side of parent window to have consistent visibility. Usually frequently used content is pinned for easier and constant access.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TR5B3hU7gGI/AAAAAAAAHCI/xE6FK5GRkuI/s1600-h/image3%5B1%5D.png"&gt;&lt;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="http://lh5.ggpht.com/_LOoKjxVTcbc/TRjYPQfT-QI/AAAAAAAAHCM/ejC-ohNKoCo/image3_thumb.png?imgmax=800" width="166" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;2. Auto hidden state – Less frequently used windows can be auto hidden so when mouse is not hovering over them they collapse into a condensed form (which I refer to as header). When mouse hovers over the headers, full window slides out from the docked side.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LOoKjxVTcbc/TRjYPjdfdHI/AAAAAAAAHCQ/lcYuQ_Jtjic/s1600-h/image6%5B1%5D.png"&gt;&lt;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="http://lh5.ggpht.com/_LOoKjxVTcbc/TRjYQCz8qmI/AAAAAAAAHCU/pr_fJa9Eg8k/image6_thumb.png?imgmax=800" width="188" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. Document state – When used as a document, dockable windows can merge as tab items within a tab control.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LOoKjxVTcbc/TRjYQYKM_7I/AAAAAAAAHCc/trQJ7db_AIw/s1600-h/image9%5B1%5D.png"&gt;&lt;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="http://lh3.ggpht.com/_LOoKjxVTcbc/TRjYQaMJBBI/AAAAAAAAHCk/sBFh_08QP_c/image9_thumb.png?imgmax=800" width="644" height="419" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;4. Floating – Usual floating windows &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TRjYQsUlMEI/AAAAAAAAHBg/rIx0HOJX10U/s1600-h/image%5B14%5D.png"&gt;&lt;img style="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="http://lh4.ggpht.com/_LOoKjxVTcbc/TRjYQ8qYzXI/AAAAAAAAHBk/goaB0dJrZ4A/image_thumb%5B4%5D.png?imgmax=800" width="244" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Docking window support is provided by DockPane control that is derivative of HeaderedContentControl. In addition to Header and Content properties that it inherits from HeaderedContentControl, it also contains the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Icon – Icon for the docked window&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;CondencedDockPanelTemplate – Template for condensed DockPane&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;CondencedDockPanel – Condenced form of DockPane&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;DockPaneState – State of the dock pane&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;DockPane also contains the following events:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Close – Close event&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;TogglePin – Toggling of pin / auto-hide button&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;HeaderDrag – Notification that user has started to drag header (title) of the DockPane&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;Default theme for DockPane is defined in the DockPane.xaml resource dictionary within MixModes.Synergy.Themes project.&lt;/p&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;Document Containers&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;DockPane(s) are contained within document containers. Document container is modeled via DocumentContainer class which is derivative of ContentControl. DocumentContainer can be in one of the following (mutually exclusive) states:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Empty – DocumentContainer does not contain any DockPane&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;ContainsDocuments – DocumentContainer contains one or more DockPane(s) as documents&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;SplitHorizontally – DocumentContainer is split horizontally&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;SplitVertically - DocumentContainer is split vertically&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TRjYRU5a_xI/AAAAAAAAHCs/mvgu9weTFOs/s1600-h/image24%5B16%5D.png"&gt;&lt;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="http://lh5.ggpht.com/_LOoKjxVTcbc/TRjYSPDMQ3I/AAAAAAAAHCw/lka6WcuTE8k/image24_thumb%5B15%5D.png?imgmax=800" width="704" height="369" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;DocumentContainer is complex in terms of its template since it is required to represent either a split view or a tabbed view. I have used a persistent TabControl within the template that is hidden if Content property is ever non-null. Content of-course is used exclusively to contain split views via Grid with two children DocumentContainer.&lt;/p&gt;  &lt;p align="justify"&gt;DocumentContainer contains the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;State – State of the DocumentContainer&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Documents – contains documents represented in TabControl&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;DocumentsTab – TabControl containing documents&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;DockIllustrationPanel – This is a panel which contains docking illustration points indicating to the user where a content should be docked. If user drags a DockPane to any one of these points it gets docked at the respective position. The image below shows content of the DockIllustrationPanel:        &lt;br /&gt;        &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TRjYSoVptpI/AAAAAAAAHBw/Gu6tJel5fbM/s1600-h/image%5B20%5D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 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="http://lh4.ggpht.com/_LOoKjxVTcbc/TRjYS_AIOKI/AAAAAAAAHB0/uZjl-iosS3E/image_thumb%5B6%5D.png?imgmax=800" width="138" height="132" /&gt;&lt;/a&gt;&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;DocumentContainer contains the following methods:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;AddDockPane(DockPane, ContentDockPoint) – Adds a DockPane as a docked window&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;AddDocumentContainers(IEnumerable&amp;lt;DocumentContainer&amp;gt;, bool) – Splits and add child DocumentContainers&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;AddDocument(DockPane) – Adds a DockPane as a tabbed document&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;RemoveDocument(DockPane) – Removes a DockPane as a tabbed document&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;The template of DocumentContainer contains the following visuals in layers (bottom visuals are in increasing Z-Order):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;TabControl (PART_DOCUMENTS) – Bound to Documents property of DocumentContainer&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;ContentPresenter – This is where split children are added&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Grid (PART_DOCK_POINTS) – Panel for hosting dock illustration points&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Grid (PART_DOCK_ILLUSTRATION) – DockIllustrationPanel for illustrating future docking via cues&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h3 align="justify"&gt;&lt;font size="3"&gt;Windows Manager&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;Windows manager is the component that binds DockPanel(s) and DocumentContainer(s) together to provide window management functionality in applications. In addition, window manager contains auto-hide and pinned dock points on all four window sides so DockPane(s) can be pinned or auto hidden outside of the DocumentContainer(s). WindowsManager also contains the root DocumentContainer that can host documents in tab control or nested-split DocumentContainer instances hosting documents.&lt;/p&gt;  &lt;p&gt;WindowsManager has the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;DockPaneIllustrationStyle – Illustration for docking a window within WindowsManager or DocumentsContainer &lt;/li&gt;    &lt;li&gt;DockIllustrationContentStyle – Illustration for merging documents while dragging a DockPane in TabControl &lt;/li&gt;    &lt;li&gt;ActiveWindowsManager – Static property indicating a WindowsManager undergoing the drag operation &lt;/li&gt;    &lt;li&gt;DraggedPane – DockPane that is being dragged &lt;/li&gt;    &lt;li&gt;&amp;lt;Orientation&amp;gt;WindowHeaders – StackPanel containing condensed auto-hidden DockPane(s) &lt;/li&gt;    &lt;li&gt;&amp;lt;Orientation&amp;gt;PinnedWindows – DockPanel containing pinned DockPane(s) &lt;/li&gt;    &lt;li&gt;DocumentContainer – Root document container &lt;/li&gt;    &lt;li&gt;DockingIllustrationPanel – Docking illustration panel for future pinned DockPanel(s) &lt;/li&gt;    &lt;li&gt;PopupArea – DockPanel where auto-hidden DockPane(s) slide out when mouse hovers upon the condensed headers &lt;/li&gt;    &lt;li&gt;FloatingPanel – Canvas that contains floating DockPane(s) &lt;/li&gt;    &lt;li&gt;DockingPanel – DockPanel that contains dock points for pinned windows as shown in image below:      &lt;br /&gt;      &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_LOoKjxVTcbc/TRjYTXskNzI/AAAAAAAAHC4/pfBmTAJZrzw/s1600-h/image30%5B2%5D.png"&gt;&lt;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="http://lh4.ggpht.com/_LOoKjxVTcbc/TRjYTSie4jI/AAAAAAAAHDA/cAh8iBhNiNU/image30_thumb%5B1%5D.png?imgmax=800" width="644" height="338" /&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;WindowsManager has the following methods:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;AddPinnedWindow(DockPane, Dock) – Adds a pinned DockPane &lt;/li&gt;    &lt;li&gt;AddAutoHideWindow(DockPane, Dock) – Adds an auto-hidden DockPane &lt;/li&gt;    &lt;li&gt;AddFloatingWindow(DockPane) – Adds a floating DockPane &lt;/li&gt;    &lt;li&gt;RemoveDockPane(DockPane) – Removes a DockPane from (pinned, auto-hidden or floating portion of ) WindowsManager &lt;/li&gt;    &lt;li&gt;Clear – Clears the WindowManager of all DockPane(s) &lt;/li&gt;    &lt;li&gt;StartDockPaneStateChangeDetection – Starts state monitoring for DraggedPane &lt;/li&gt;    &lt;li&gt;StopDockPaneStateChangeDetection – Stops state monitoring for DraggedPane &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;&lt;font size="3"&gt;How it all works together&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;The image below illustrates the relationship between various components of the docking solution:&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://lh4.ggpht.com/_LOoKjxVTcbc/TR5B7S3g-0I/AAAAAAAAHDE/SgynVz_5kJs/s1600-h/1%5B6%5D.png"&gt;&lt;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="1" border="0" alt="1" src="http://lh6.ggpht.com/_LOoKjxVTcbc/TR5B7jZ19gI/AAAAAAAAHDM/wnPFhLkCYA0/1_thumb%5B2%5D.png?imgmax=800" width="658" height="423" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Structurally WindowsManager is the encompassing component that contains pinned and auto-hidden DockPane(s). It also contains the root DocumentContainer. DocumentContainer on the other hand can either contain documents in the tab control by wrapping DockPane within DocumentContent instance or it can contain split windows where a grid holds child DocumentContainer(s) each of which recursively can either contain documents or further child DocumentContainer(s).&lt;/p&gt;  &lt;p align="justify"&gt;WindowsManager constantly monitors the state change of DockPane. When a DockPane drag is detected, it is placed on the FloatingPanel canvas of WindowsManager as a floating window that can be dragged around. During a drag of a DockPane hit testing is turned off on the DockPane so mouse events can flow down to controls below it such as WindowsManager and DocumentContainer.&lt;/p&gt;  &lt;p align="justify"&gt;For orchestrating drag and drop and docking functionality I have used a behavior driven approach. The idea is to expose functional end-points (such as methods and properties) on visual entities such as DockPane, DocumentContainer and WindowsManager and use behaviors to orchestrate and call these functional end-points. This approach also resulted in manageable-encapsulated components that were easier to trace and test.&lt;/p&gt;  &lt;p align="justify"&gt;DockPointBehavior monitors the dragged DockPane over WindowsManager and pops up dock points for pinning it. ContentPointBehavior on the other hand injects similar functionality within DocumentContainer for splitting and tab merging purpose.&lt;/p&gt;  &lt;p align="justify"&gt;Both WindowsManager and DocumentContainer have dock illustration grid containing the docking behavior. DockPointBehavior behavior illustrates pinned docking illustration on&amp;#160; WindowsManager whereas ContentDockBehavior illustrates splitting and tab merging illustration on DocumentContainer.&lt;/p&gt;  &lt;h3&gt;&lt;font size="3"&gt;Using the code&lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;Using WindowsManager is extremely simple:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Import the namespace in the xaml      &lt;br /&gt;&lt;a title="xmlns:visualFx=&amp;quot;http://mixmodes.com/visualFx&amp;quot;" href="xmlns:visualFx=&amp;quot;http://mixmodes.com/visualFx&amp;quot;"&gt;&lt;font color="#000000"&gt;xmlns:visualFx=&amp;quot;http://mixmodes.com/visualFx&amp;quot;&lt;/font&gt;&lt;/a&gt;       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Drop the WindowsManager in the xaml      &lt;br /&gt;&amp;lt;visualFx:WindowsManager x:Name=&amp;quot;WindowsManager&amp;quot;/&amp;gt;       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Start creating DockPane and insert them within WindowsManager / DocumentContainer      &lt;br /&gt;DockPane pane = new DockPane();       &lt;br /&gt;pane.Header = …       &lt;br /&gt;pane.Content = ….       &lt;br /&gt;WindowsManager.AddPinnedWindow(pane, Dock.Top);       &lt;br /&gt;// OR       &lt;br /&gt;WindowsManager.AddAutoHideWindow(pane, Dock.Left);       &lt;br /&gt;// OR       &lt;br /&gt;// Assuming DocumentContainer is either in Empty or ContainsDocuments state       &lt;br /&gt;WindowsManager.DocumentContainer.AddDocument(pane); &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;&lt;font size="3"&gt;Serializing Window State&lt;/font&gt;&lt;/h3&gt;  &lt;p align="justify"&gt;Out of the box, Synergy provides XML serialization of window states through XmlWindowsManagerSerializer and XmlWindowsManagerDeserializer classes. Custom serialization is supported via specialization of base classes WindowsManagerSerializer and WindowsManagerDeserializer respectively.&lt;/p&gt;  &lt;p align="justify"&gt;XML serialization of WindowsManager using XmlWindowsManagerSerializer requires two pieces of information during construction:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p align="justify"&gt;DockPane writer – An Action&amp;lt;XmlElement, DockPane&amp;gt; instance that can write additional metadata about a DockPane to the XmlElement.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p align="justify"&gt;Document writer – A Func&amp;lt;DocumentContent, string&amp;gt; instance that takes in a DocumentContent and returns a string representation of the content. Note: DocumentContent.DockPane property returns the associated DockPane, however the Header and Content properties of DockPane are set to null. To access Header and Content property, use the Header and Content properties of DocumentContent instance directly.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;Once XmlWindowsManagerSerializer instance is created, a call to Serialize(Stream, WindowsManager) method serializes WindowsManager to the stream.&lt;/p&gt;  &lt;p align="justify"&gt;Similar to serialization process, deserialization process requires an instance of Action&amp;lt;DockPane, string&amp;gt; within the constructor of XmlWindowsManagerDeserializer to de-serialize a DockPane from previously saved string representation. Deserialization does not require additional Action to realize DocumentContent since DocumentContent is inherently a serialization wrapper for DockPane.&lt;/p&gt;  &lt;p align="justify"&gt;Once XmlWindowsManagerDeserializer&amp;#160; instance is created, a call to Deserialize(Stream, WindowsManager) deserializes the WindowsManager to previously saved state.&lt;/p&gt;  &lt;p align="justify"&gt;All the docking functionality can be exercised by using the sample app (Synergy project) with the source code. Any comments or suggestions or bug-reports are as usual always welcome. Happy coding !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-997336511222342604?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/997336511222342604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=997336511222342604' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/997336511222342604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/997336511222342604'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2010/12/building-docking-window-management.html' title='Building a docking window management solution in WPF'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_LOoKjxVTcbc/TRjYPQfT-QI/AAAAAAAAHCM/ejC-ohNKoCo/s72-c/image3_thumb.png?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-7629316003959852968</id><published>2010-12-23T13:09:00.001-08:00</published><updated>2010-12-23T14:43:25.324-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Value converters'/><category scheme='http://www.blogger.com/atom/ns#' term='Markup extensions'/><category scheme='http://www.blogger.com/atom/ns#' term='CodeProject'/><category scheme='http://www.blogger.com/atom/ns#' term='Attached properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='Dependency Properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Dynamic value converters'/><category scheme='http://www.blogger.com/atom/ns#' term='Data Binding'/><title type='text'>Dynamically bind value converters to elements in XAML</title><content type='html'>&lt;p&gt;Recently I faced a scenario where I wanted to create a generic control template in WPF for a user control that refers to value converters dynamically in order to render parts of the control. &lt;/p&gt;  &lt;p&gt;Depending on the enumeration passed as the parameter, converter is supposed to render different aspect of the object. The actual formatter is unknown at the base control level except for the enumeration.&lt;/p&gt;  &lt;p&gt;Concrete implementation/usage of the control should specify the converter as its property. I tried doing this in XAML:&lt;/p&gt;  &lt;p&gt;SomeProperty = {Binding Converter={Binding MyConverterProperty} }&lt;/p&gt;  &lt;p&gt;The above will result in runtime exception as Converter property is not DependencyProperty within BindingMarkupExtension.&lt;/p&gt;  &lt;p&gt;There are three ways of achieving above:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;1. Create a virtual converter and have object implement IConvertable:&lt;/p&gt;  &lt;p&gt;One can declare IConvertable interface that provides a converter:&lt;/p&gt;  &lt;p&gt;public interface IConvertable   &lt;br /&gt;{    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; IValueConverter Converter {get;}    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;and a &amp;quot;virtual&amp;quot; converter&lt;/p&gt;  &lt;p&gt;public class VirtualConverter : IValueConverter   &lt;br /&gt;{&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public void Convert(object value, ....)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IValueConverter converter;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if ((value is IConvertible) &amp;amp;&amp;amp; ((converter = (value as IConvertible) != null)))    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; converter.Convert(....);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new InvalidOperationException();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; :    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; :    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;And now you can create a static resource of type VirtualConverter and use Binding normally specifying VirtualConverter as the converter.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;2. Implement IConvertible but instead of creating Virtual converter, declare a markup extension that takes in IConvertible and returns IValueConverter. Then your markup will look like:&lt;/p&gt;  &lt;p&gt;SomeProperty = &amp;quot;{Binding Converter={ConverterExtension Source={Binding}}}&amp;quot;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;3. Use attached property to define Converter on an object rather than implementing IConvertible and specify it as converter in binding.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-7629316003959852968?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/7629316003959852968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=7629316003959852968' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/7629316003959852968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/7629316003959852968'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2010/12/dynamically-bind-value-converters-to.html' title='Dynamically bind value converters to elements in XAML'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-7681462648055510846</id><published>2010-12-14T09:03:00.001-08:00</published><updated>2010-12-26T19:04:04.708-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='MixModes Synergy 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF Behaviors'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF Handlers'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><category scheme='http://www.blogger.com/atom/ns#' term='Behavior Handler Pattern'/><title type='text'>Introducing MixModes Synergy 2010</title><content type='html'>&lt;p align="justify"&gt;For the past few months I have been engaged in the development of Windows Presentation Foundation (WPF) based SDK called MixModes Synergy 2010, under my company MixModes Inc. Synergy is a WPF toolkit that unleashes the power of WPF via simpler programming constructs and provides out of the box custom controls that allows Rapid Application Development of line of business applications. MixModes Synergy 2010 can be downloaded &lt;a href="http://mixmodes.com/Synergy.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p align="justify"&gt;This SDK will be ongoing development that MixModes Inc. will pursue to provide best possible support for WPF and Silverlight development. Some of the features in version 1.0 include:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Base framework for WPF development&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Easy and type-safe adoption of Model-View-ViewModel pattern&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Custom visual adorners&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Logical behaviors&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Out of the box custom controls&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;MixModes Synergy 2010 is free for all uses and is MixModes Inc.’s initiative to contribute to the developer community. In this blog I will uncover the solutions Synergy provides in each of the above categories.&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h4 align="justify"&gt;Base framework for WPF development&lt;/h4&gt;  &lt;h5 align="justify"&gt;Commanding&lt;/h5&gt;  &lt;p align="justify"&gt;CommandBase class provides a flexible implementation for custom commands. This class works on an Action&amp;lt;object&amp;gt; instance for command invocation and an optional Predicate&amp;lt;object&amp;gt; for command execution evaluation. If predicate is not specified, it is assumed that command can execute at any time. Also CommandBase exposes CanExecuteChanged event that is registered with CommandManager which then re-queries validity of command execution based on user interaction with the application.&lt;/p&gt;  &lt;p align="justify"&gt;Simply speaking one can instantiate a command base class as follows:&lt;/p&gt;  &lt;p align="justify"&gt;CommandBase myCommand = new CommandBase(arg=&amp;gt;DoFoo(arg), arg=&amp;gt; CanFoo(arg));&lt;/p&gt;  &lt;h5 align="justify"&gt;&amp;#160;&lt;/h5&gt;  &lt;h5 align="justify"&gt;FrameworkElement extensions&lt;/h5&gt;  &lt;p align="justify"&gt;FrameworkElementExtensions class contains a list of extension methods for FrameworkElement instances that help in finding logical and visual parents of specified type, clearing adorner layer for element, enforcing element size and displaying tooltips very easily.&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h5 align="justify"&gt;Window enhancements&lt;/h5&gt;  &lt;p align="justify"&gt;CustomWindow class provides a fast way to create a custom window by just declaring a template for custom window and specifying the named parts for window controls.&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h5 align="justify"&gt;Dialog window enhancements&lt;/h5&gt;  &lt;p align="justify"&gt;DialogWindow provides a true dialog box look and feel for modal dialogs by setting appropriate window style on the dialogs. This fixes WPF bugs around inability of dialog windows to hide control box.&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h5 align="justify"&gt;DependencyProperty change detection&lt;/h5&gt;  &lt;p align="justify"&gt;ObservableDependencyProperty class can monitor change in a dependency property of a dependency object without need for separate events. To monitor changes in a dependency property for a dependency object one needs to supply a callback delegate of type DependencyPropertyChangedEventHandler. Following code illustrates usage of ObservableDependencyProperty:&lt;/p&gt;  &lt;p align="left"&gt;ObservableDependencyProperty descriptor = new ObservableDependencyProperty(    &lt;br /&gt;typeof(string),&amp;#160; &lt;br /&gt;TextBox.TextProperty,     &lt;br /&gt;OnTextChanged);&lt;/p&gt;  &lt;p align="justify"&gt;descriptor.AddValueChanged(myTextBox);&lt;/p&gt;  &lt;p align="justify"&gt;void OnTextChanged(object sender, DependencyPropertyChangedEventArgs e)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; TextBox changedBox = sender as TextBox;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string oldValue = e.OldValue as string;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string newValue = e.NewValue as string;     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;If monitoring of a specific dependency property on a list of elements is required, ObservableDependencyPropertyCollection provides the necessary plumbing for ease of tracking changes.&lt;/p&gt;  &lt;p align="justify"&gt;_dockPaneStateMonitorList = new ObservableDependencyPropertyCollection&amp;lt;DockPane&amp;gt;(DockPane.DockPaneStateProperty);    &lt;br /&gt;_dockPaneStateMonitorList.DependencyPropertyChanged += OnDockPaneStateChanged;     &lt;br /&gt;    &lt;br /&gt;_dockPaneStateMonitorList.Add(myDockPane);     &lt;br /&gt;    &lt;br /&gt;private void OnDockPaneStateChanged(object sender, DependencyPropertyChangedEventArgs e)     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPane pane = sender as DockPane;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DockPaneState state = (DockPaneState)e.NewValue;     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h4 align="justify"&gt;Easy and type-safe adoption of Model-View-ViewModel pattern&lt;/h4&gt;  &lt;p align="justify"&gt;ViewModelBase class provides a type safe RaisePropertyChanged method for derived classes and hence provides compile time property name checks. Rather than passing in a string as the property name, derived classes raise PropertyChanged event as follows:&lt;/p&gt;  &lt;p align="justify"&gt;RaisePropertyChanged(x=&amp;gt;this.MyProperty);&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h4 align="justify"&gt;Custom visual adorners&lt;/h4&gt;  &lt;p align="justify"&gt;MixModes Synergy allows for visual creation of adorners. In fact any visual can be transformed into a adorner with practically few lines of code. All this magic is done through the use of ContentAdornerBase class that makes creating visual adorners no different than creating a user control. It just takes a few steps to create a visual adorner:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Create a visual resource in your resource dictionary – This can be done using Blend designer. Ensure that x:Shared is set to False on the resource. This means that anytime you host the resource on multiple elements, a copy of visual tree shall be created preventing duplicate parenting issues.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;If the resource dictionary is different from default application resource dictionary, place a link in the merged dictionary section of default application dictionary to load it.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Derive a class from ContentAdornerBase; load and pass in the visual resource from resource dictionary and pass it onto the base constructor.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Add the derivative class to adorned element’s adorner layer.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;As an example, let’s assume that you want to create a reusable adorner that helps resize adorned element. Following the steps above you could define a resource in the resource dictionary ResizableAdorner.xaml:&lt;/p&gt;  &lt;p align="justify"&gt;&amp;lt;Grid x:Key=&amp;quot;ResizableAdorner&amp;quot; x:Shared=&amp;quot;False&amp;quot;&amp;gt;    &lt;br /&gt;:     &lt;br /&gt;&amp;lt;/Grid&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;Link ResizableAdorner.xml to your application resource dictionary as one of the merged dictionary:&lt;/p&gt;  &lt;p&gt;&amp;lt;ResourceDictionary xmlns=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/a&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; xmlns:x=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/a&gt;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ResourceDictionary.MergedDictionaries&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ResourceDictionary Source=&amp;quot;ResizableAdorner.xaml&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; :     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/ResourceDictionary.MergedDictionaries&amp;gt;     &lt;br /&gt;&amp;lt;/ResourceDictionary&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;Create a class ResizingAdorner deriving from ContentAdornerBase as follows:&lt;/p&gt;  &lt;p&gt;/// &amp;lt;summary&amp;gt;    &lt;br /&gt;/// Resizing adorner     &lt;br /&gt;/// &amp;lt;/summary&amp;gt;     &lt;br /&gt;internal class ResizingAdorner : ContentAdornerBase     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// Initializes a new instance of the &amp;lt;see cref=&amp;quot;ResizingAdorner&amp;quot;/&amp;gt; class.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;param name=&amp;quot;adornedElement&amp;quot;&amp;gt;The element to bind the adorner to&amp;lt;/param&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;exception cref=&amp;quot;ArgumentNullException&amp;quot;&amp;gt;adornedElement is null&amp;lt;/exception&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; internal ResizingAdorner(UIElement adornedElement)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : base(adornedElement, Application.Current.Resources[“ResizableAdorner”] as FrameworkElement)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AttachNamedParts();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// Attaches the named parts     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private void AttachNamedParts()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Use FindElement&amp;lt;T&amp;gt; to find named parts and attach behavior here     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Finally just place the adorner to adorned element’s adorner layer:&lt;/p&gt;  &lt;p&gt;AdornerLayer layer = AdornerLayer.GetAdornerLayer(someFrameworkElement);    &lt;br /&gt;if (layer != null)     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; layer.Add(new ResizingAdorner(someFrameworkElement));     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;That’s all the steps you need to create a visual adorner !&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Logical behaviors&lt;/h4&gt;  &lt;p align="justify"&gt;Logical behavior is a new concept introduced by MixModes Synergy that decouples behavior from its visual parent. The idea is to define visual behavior in control templates that can then bind to an ancestor visual element or a template parent in attaching the behavior. To create a logical behavior, follow the following steps:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Derive a behavior from LogicalParentBehavior&amp;lt;T&amp;gt; class and supply the logical parent as the generic parameter during derived class definition. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;In the overridden OnAttached method, call base.OnAttached and then access LogicalParent property of the base class to access the logical parent to attach behavior.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;In the XAML just declare behavior in the usual fashion to any visual element.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h4 align="justify"&gt;Out of the box custom controls&lt;/h4&gt;  &lt;p align="justify"&gt;MixModes Synergy provides out of the box custom controls that are easily consumable from your WPF based applications. All the controls released as part of MixModes Synergy 2010 SDK are completely look-less and can be custom themed on top of the standard themes that ships as part of the SDK. MixModes will release additional custom controls on a regular basis to enrich Synergy and provide out of the box support in the development for line of business applications.&lt;/p&gt;  &lt;p align="justify"&gt;One major control release in the current release is the window docking solution similar to docking windows in Microsoft Visual Studio. Using docking window control is very simple. In your XAML just add the WindowManager control:&lt;/p&gt;  &lt;p align="justify"&gt;&amp;lt;visualFx:WindowsManager x:Name=&amp;quot;WindowsManager&amp;quot;/&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;WindowsManager as the name suggests is the primary manager for windows in docking solution. Each dockable window is an instance of DockPane class which is a derivative of HeaderedContentControl. Hence DockPane instance can have a Header (which serves as the title of the DockPane) and a Content (which serves as the content of the DockPane).&lt;/p&gt;  &lt;p align="justify"&gt;DockPane can be added in many different ways to the WindowsManager:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;As pinned window – via WindowsManager.AddPinnedWindow(DockPane, Dock) method&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;As auto hidden window – via WindowsManager.AddAutoHideWindow(DockPane, Dock) method&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;As floating window – via WindowsManager.AddFloatingWindow(DockPane) method&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;As a document in the main document area – via WindowsManager.DocumentContainer.AddDocument(DockPane) method&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;DocumentContainer is the component that organizes documents within WindowsManager (this excludes pinned, auto-hidden and floating windows since they are not considered documents).&lt;/p&gt;  &lt;p align="justify"&gt;MixModes Synergy 2010 also provides window state serialization and deserialization for your application environment to preserve and load the window environment of any complexity.&lt;/p&gt;  &lt;p align="justify"&gt;Out of the box, Synergy provides XML serialization of window states through XmlWindowsManagerSerializer and XmlWindowsManagerDeserializer classes. Custom serialization is supported via specialization of base classes WindowsManagerSerializer and WindowsManagerDeserializer respectively.&lt;/p&gt;  &lt;p align="justify"&gt;XML serialization of WindowsManager using XmlWindowsManagerSerializer requires two pieces of information during construction:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;DockPane writer – An Action&amp;lt;XmlElement, DockPane&amp;gt; instance that can write additional metadata about a DockPane to the XmlElement.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Document writer – A Func&amp;lt;DocumentContent, string&amp;gt; instance that takes in a DocumentContent and returns a string representation of the content. Note: DocumentContent.DockPane property returns the associated DockPane, however the Header and Content properties of DockPane are set to null. To access Header and Content property, use the Header and Content properties of DocumentContent instance directly.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;Once XmlWindowsManagerSerializer instance is created, a call to Serialize(Stream, WindowsManager) method serializes WindowsManager to the stream.&lt;/p&gt;  &lt;p align="justify"&gt;Similar to serialization process, deserialization process requires an instance of Action&amp;lt;DockPane, string&amp;gt; within the constructor of XmlWindowsManagerDeserializer to de-serialize a DockPane from previously saved string representation. Deserialization does not require additional Action to realize DocumentContent since DocumentContent is inherently a serialization wrapper for DockPane.&lt;/p&gt;  &lt;p align="justify"&gt;Once XmlWindowsManagerDeserializer&amp;#160; instance is created, a call to Deserialize(Stream, WindowsManager) deserializes the WindowsManager to previously saved state.&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;h4 align="justify"&gt;Summary&lt;/h4&gt;  &lt;p align="justify"&gt;MixModes Synergy 2010 is an ongoing project and several additions will be made to the SDK based on customer requests. Everyone is encouraged to download and play with the SDK and please send me your questions and suggestions &lt;a href="mailto:info@mixmodes.com" target="_blank"&gt;here&lt;/a&gt;. Thank you all very much.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-7681462648055510846?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/7681462648055510846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=7681462648055510846' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/7681462648055510846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/7681462648055510846'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2010/12/introducing-mixmodes-synergy-2010.html' title='Introducing MixModes Synergy 2010'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-2346740582188557357</id><published>2010-08-02T10:26:00.001-07:00</published><updated>2010-08-02T10:27:57.664-07:00</updated><title type='text'>Power of Templates In Control Development Within Windows Presentation Foundation</title><content type='html'>&lt;h4&gt;Background&lt;/h4&gt;  &lt;p align="justify"&gt;WPF is very powerful framework in terms of flexibility in defining visual characteristics of the UI. The visual designing aspect of WPF allows for developer – designer collaboration (and separation of concerns). In this tutorial I will take a practical example of a card game and illustrate how to model a playing card in WPF and define templates for defining visual aspect of the card as per the sign and the value of the card.&lt;/p&gt;  &lt;h4&gt;Source Code&lt;/h4&gt;  &lt;p&gt;Complete source code of the article and be found here&lt;/p&gt; &lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-a521a90cb40d14ff.office.live.com/embedicon.aspx/BloggerContent/CustomControlExample.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;h4&gt;Evaluating development options&lt;/h4&gt;  &lt;p align="justify"&gt;I wanted to model a playing card so it is highly reusable and theme-able so other developers and designers can consume it easily. At a basic level a card must contain its value and type and be selectable. There were several development options available in WPF I could opt for:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Take an existing WPF control and theme it to represent a card and use attached properties to set its value and card type&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Define a custom control and code in all the above functionality and define its theme to represent a card&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Combine the above two methods - derive from an existing WPF control and define templates and additional properties on it&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;First approach does not allow me to declare discoverable properties of a card on existing control. While attached properties are great, they are bit hard to discover. Card’s properties are very prominent and frequently used, so I opted for a more out of the box – self contained control.&lt;/p&gt;  &lt;p align="justify"&gt;Second approach requires me to develop a custom control from scratch. So this approach is ruled out as well.&lt;/p&gt;  &lt;p align="justify"&gt;I prefer the third approach where I can leverage some capabilities of an existing WPF control and define my own custom properties on top to provide an out of box experience. And since this will be a custom control, I can define out of the box – default theme for this control. Since a playing card can be selected – deselected I choose to derive from ToggleButton control that provides with selection capabilities.&lt;/p&gt;  &lt;h4&gt;Template support&lt;/h4&gt;  &lt;p align="justify"&gt;Playing card supports multiple theme depending on the type and value of the card. This information is captured within CardTemplate class a collection of which is defined as CardTemplateCollection.&lt;/p&gt;  &lt;p&gt;public sealed class CardTemplate    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public ControlTemplate Template { get; set; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public CardValue Value { get; set; }     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;public sealed class CardTemplateCollection : Collection&amp;lt;CardTemplate&amp;gt;    &lt;br /&gt;{     &lt;br /&gt;}&lt;/p&gt;  &lt;p align="justify"&gt;Deriving from Collection&amp;lt;T&amp;gt; allows for native XAML serialization and one can enclose objects easily within collection tag.&lt;/p&gt;  &lt;p&gt;PlayingCard class contains CardTemplateCollection as its CardTemplates dependency property.&lt;/p&gt;  &lt;p&gt;private static DependencyProperty CardTemplatesProperty = DependencyProperty.Register(    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;CardTemplates&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(CardTemplateCollection),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(PlayingCard),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyMetadata(new CardTemplateCollection(), UpdateTemplate));&lt;/p&gt;  &lt;p align="justify"&gt;Notice how a new CardTemplateCollection is set as a default property value. This is so because whenever we derive from Collection&amp;lt;T&amp;gt; and leverage XAML serialization capability, we need a valid object before it is assigned in XAML.&lt;/p&gt;  &lt;p align="justify"&gt;PlayingCard also contains a method UpdateTemplate which picks the right template for the card depending upon card value.&lt;/p&gt;  &lt;p&gt;private void UpdateTemplate()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; CardTemplateCollection templates = CardTemplates;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ControlTemplate selectedTemplate = null;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (templates != null)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (CardTemplate template in templates)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (template.Value == CardValue)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; selectedTemplate = template.Template;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; Template = selectedTemplate;    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Following is the complete listing of PlayingCard class:&lt;/p&gt;  &lt;p&gt;public class PlayingCard : ToggleButton    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private static DependencyProperty CardTypeProperty = DependencyProperty.Register(&amp;quot;CardType&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(CardType),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(PlayingCard),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyMetadata(CardType.Club)); &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private static DependencyProperty CardValueProperty = DependencyProperty.Register(&amp;quot;CardValue&amp;quot;,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(CardValue),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(PlayingCard),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyMetadata(CardValue.Two, UpdateTemplate)); &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private static DependencyProperty CardTemplatesProperty = DependencyProperty.Register(&amp;quot;CardTemplates&amp;quot;,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(CardTemplateCollection),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(PlayingCard),     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new PropertyMetadata(new CardTemplateCollection(), UpdateTemplate)); &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; static PlayingCard()    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DefaultStyleKeyProperty.OverrideMetadata(typeof(PlayingCard), new FrameworkPropertyMetadata(typeof(PlayingCard)));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public CardType CardType     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return (CardType)GetValue(CardTypeProperty); }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set { SetValue(CardTypeProperty, value); }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public CardValue CardValue    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return (CardValue)GetValue(CardValueProperty); }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set { SetValue(CardValueProperty, value); }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public CardTemplateCollection CardTemplates    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return (CardTemplateCollection)GetValue(CardTemplatesProperty); }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set { SetValue(CardTemplatesProperty, value); }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private void UpdateTemplate()    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardTemplateCollection templates = CardTemplates;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ControlTemplate selectedTemplate = null; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (templates != null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (CardTemplate template in templates)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (template.Value == CardValue)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; selectedTemplate = template.Template;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Template = selectedTemplate;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private static void UpdateTemplate(DependencyObject d, DependencyPropertyChangedEventArgs e)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PlayingCard card = d as PlayingCard;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; card.UpdateTemplate();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Notice we call UpdateTemplate method whenever CardValue or CardTemplates properties are changed.&lt;/p&gt;  &lt;p align="justify"&gt;Next step is to define and populate all the templates within the default theme of the PlayingCard control. But before we embark on that there are two pieces of visual information we would need in order to theme the card right:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;The sign of the card – Depending on the type of the card we need the right symbol to appear in the template. This is achieved by CardTypeToImageConverter. Basically we define this converter with a property of type CardImageTypeCollection which contains objects of type CardImageType. CardImageType just contains CardType enum (that denotes type of card: Club, Diamond, Heart, Spade) and string uri of related image&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public sealed class CardTypeImage    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public CardType CardType { get; set; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public string ImageSource { get; set; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public sealed class CardTypeImageCollection : Collection&amp;lt;CardTypeImage&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public sealed class CardTypeToImageConverter : IValueConverter      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public CardTypeToImageConverter()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageCollection = new CardTypeImageCollection();&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public CardTypeImageCollection ImageCollection { get; set; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public object Convert(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PlayingCard card = value as PlayingCard;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if ((card != null) &amp;amp;&amp;amp; (ImageCollection != null))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (CardTypeImage cardTypeImage in ImageCollection)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (card.CardType == cardTypeImage.CardType)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return cardTypeImage.ImageSource;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return null;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new NotImplementedException();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt; &lt;/blockquote&gt;  &lt;p align="justify"&gt;As can be seen this converter takes in PlayingCard as input and returns the uri of the symbol image from searching its ImageCollection.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Image of the character if card represents a character – If PlayingCard is of value Ace, King, Queen and Jack we need access to the right character image in the template. This is delegated to CardTypeToCharacterImageConverter as follows:&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public sealed class CardCharacterImage      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public CardType CardType { get; set; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public CardValue CardValue { get; set; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public string ImageSource { get; set; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public sealed class CardCharacterImageCollection : Collection&amp;lt;CardCharacterImage&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public sealed class CardTypeToCharacterImageConverter : IValueConverter      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public CardTypeToCharacterImageConverter()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageCollection = new CardCharacterImageCollection();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public CardCharacterImageCollection ImageCollection { get; set; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public object Convert(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PlayingCard card = value as PlayingCard;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if ((card != null) &amp;amp;&amp;amp; (IsCharacterCard(card)))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (CardCharacterImage cardCharacterImage in ImageCollection)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if ((card.CardValue == cardCharacterImage.CardValue) &amp;amp;&amp;amp;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; (card.CardType == cardCharacterImage.CardType))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return cardCharacterImage.ImageSource;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return null;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new NotImplementedException();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private bool IsCharacterCard(PlayingCard card)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; switch (card.CardValue)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Two:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Three:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Four:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Five:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Six:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Seven:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Eight:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Nine:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case CardValue.Ten:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return false;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; default:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return true;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p&gt;Hence depending on the type and value of the character card, this converter returns the right image uri for the card.&lt;/p&gt;    &lt;p&gt;Now we have all we need to define our templates for the PlayingCard control.&lt;/p&gt;    &lt;p&gt;First let’s define CardTypeToImageConverter shared converter in resource dictionary that themes will use:&lt;/p&gt;    &lt;p&gt;&amp;lt;Converters:CardTypeToImageConverter x:Key=&amp;quot;CardTypeToImageConverter&amp;quot;&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardTypeToImageConverter.ImageCollection&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardTypeImageCollection&amp;gt;       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardTypeImage CardType=&amp;quot;Club&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/Club.png&amp;quot;/&amp;gt;       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardTypeImage CardType=&amp;quot;Diamond&amp;quot;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/Diamond.png&amp;quot;/&amp;gt;       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardTypeImage CardType=&amp;quot;Heart&amp;quot;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/Heart.png&amp;quot;/&amp;gt;       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardTypeImage CardType=&amp;quot;Spade&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/Spade.png&amp;quot;/&amp;gt;       &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Converters:CardTypeImageCollection&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Converters:CardTypeToImageConverter.ImageCollection&amp;gt;       &lt;br /&gt;&amp;#160; &amp;lt;/Converters:CardTypeToImageConverter&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Then let’s define CardTypeToCharacterImageConverter shared converter:&lt;/p&gt;  &lt;p&gt;&amp;lt;Converters:CardTypeToCharacterImageConverter x:Key=&amp;quot;CardTypeToCharacterImageConverter&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardTypeToCharacterImageConverter.ImageCollection&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Club&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Ace&amp;quot;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/AceClub.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Diamond&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Ace&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/AceDiamond.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Heart&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Ace&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/AceHeart.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Spade&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Ace&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/AceSpade.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Club&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Jack&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/JackClub.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Diamond&amp;quot;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Jack&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/JackDiamond.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Heart&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Jack&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/JackHeart.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Spade&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Jack&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/JackSpade.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Club&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;King&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/KingClub.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Diamond&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;King&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/KingDiamond.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Heart&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;King&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/KingHeart.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Spade&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;King&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/KingSpade.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Club&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Queen&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/QueenClub.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Diamond&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Queen&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/QueenDiamond.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Heart&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Queen&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/QueenHeart.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Converters:CardCharacterImage     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardType=&amp;quot;Spade&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CardValue=&amp;quot;Queen&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ImageSource=&amp;quot;/CardDeckSample;component/Resources/QueenSpade.png&amp;quot;/&amp;gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Converters:CardTypeToCharacterImageConverter.ImageCollection&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;/Converters:CardTypeToCharacterImageConverter&amp;gt;&lt;/p&gt;  &lt;p&gt;We also need to flip card signs in the bottom half of cards vertically so we capture this in a common style called VerticalFlipStyle:&lt;/p&gt;  &lt;p&gt;&amp;lt;Style TargetType=&amp;quot;{x:Type FrameworkElement}&amp;quot; x:Key=&amp;quot;VerticalFlipStyle&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160; &amp;lt;Setter Property=&amp;quot;RenderTransform&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;TransformGroup&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RotateTransform Angle=&amp;quot;180&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/TransformGroup&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;/Setter&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;Setter Property=&amp;quot;RenderTransformOrigin&amp;quot; Value=&amp;quot;0.5,0.5&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;lt;/Style&amp;gt; &lt;/p&gt;  &lt;p align="justify"&gt;Great now we have all the tools that we can make use of in our card templates. So let’s define templates for each of the possible card values and character cards starting with character card template:&lt;/p&gt;  &lt;p&gt;&amp;lt;ControlTemplate TargetType=&amp;quot;{x:Type local:PlayingCard}&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; x:Key=&amp;quot;CharacterCardTemplate&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Border Background=&amp;quot;{TemplateBinding Background}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; BorderBrush=&amp;quot;{TemplateBinding BorderBrush}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; BorderThickness=&amp;quot;{TemplateBinding BorderThickness}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CornerRadius=&amp;quot;4&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Source=&amp;quot;{Binding Converter={StaticResource CardTypeToCharacterImageConverter}, RelativeSource={RelativeSource TemplatedParent}}&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Border&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;/ControlTemplate&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;You can see in Source attribute of Image used in template we use CardTypeToCharacterImageConverter (declared as shared converter above) and pass in templated parent (PlayingCard) as relative source.&lt;/p&gt;  &lt;p align="justify"&gt;Now for each of the values we declare templates. I will not cover entire template list here (you can check them out in Generic.xaml in Themes folder of source code) but I will mention template for a card of value “2”&lt;/p&gt;  &lt;p&gt;&amp;lt;ControlTemplate TargetType=&amp;quot;{x:Type local:PlayingCard}&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; x:Key=&amp;quot;TwoTemplate&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Border Background=&amp;quot;{TemplateBinding Background}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; BorderBrush=&amp;quot;{TemplateBinding BorderBrush}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; BorderThickness=&amp;quot;{TemplateBinding BorderThickness}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CornerRadius=&amp;quot;4&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Grid Margin=&amp;quot;4&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Grid.RowDefinitions&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RowDefinition Height=&amp;quot;32&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RowDefinition Height=&amp;quot;32&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RowDefinition Height=&amp;quot;*&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RowDefinition Height=&amp;quot;32&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RowDefinition Height=&amp;quot;32&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Grid.RowDefinitions&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Grid.ColumnDefinitions&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ColumnDefinition Width=&amp;quot;32&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ColumnDefinition Width=&amp;quot;*&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ColumnDefinition Width=&amp;quot;32&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Grid.ColumnDefinitions&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;TextBlock Grid.Row=&amp;quot;0&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Column=&amp;quot;0&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; HorizontalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; VerticalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Text=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; FontSize=&amp;quot;26.667&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Source=&amp;quot;{Binding Converter={StaticResource CardTypeToImageConverter}, RelativeSource={RelativeSource TemplatedParent}}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Row=&amp;quot;1&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Column=&amp;quot;0&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Source=&amp;quot;{Binding Converter={StaticResource CardTypeToImageConverter}, RelativeSource={RelativeSource TemplatedParent}}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Row=&amp;quot;3&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Column=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Style=&amp;quot;{StaticResource VerticalFlipStyle}&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;TextBlock Grid.Row=&amp;quot;4&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Column=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; HorizontalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; VerticalAlignment=&amp;quot;Center&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Text=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; FontSize=&amp;quot;26.667&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Style=&amp;quot;{StaticResource VerticalFlipStyle}&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Grid Grid.Row=&amp;quot;2&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Column=&amp;quot;1&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Margin=&amp;quot;16&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Grid.RowDefinitions&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RowDefinition Height=&amp;quot;*&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RowDefinition Height=&amp;quot;*&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Grid.RowDefinitions&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Source=&amp;quot;{Binding Converter={StaticResource CardTypeToImageConverter}, RelativeSource={RelativeSource TemplatedParent}}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Row=&amp;quot;0&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Height=&amp;quot;32&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Width=&amp;quot;32&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image Source=&amp;quot;{Binding Converter={StaticResource CardTypeToImageConverter}, RelativeSource={RelativeSource TemplatedParent}}&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Grid.Row=&amp;quot;1&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Height=&amp;quot;32&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Width=&amp;quot;32&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Style=&amp;quot;{StaticResource VerticalFlipStyle}&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Grid&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Grid&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Border&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;/ControlTemplate&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;As you can see we have used both CardTypeToImageConverter to obtain sign image and used VerticalFlipStyle to flip bottom symbols vertically to get a card similar to Figure 1 below.&lt;/p&gt; &lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/TFb7DDX8BXI/AAAAAAAAG-4/_m6u0p7iLH4/CardImage.png" /&gt;   &lt;p&gt;Figure 1 – Templated spade card of value 2&lt;/p&gt;  &lt;p&gt;Finally we declare default style and template of PlayingCard as below:&lt;/p&gt;  &lt;p&gt;&amp;lt;Style TargetType=&amp;quot;{x:Type local:PlayingCard}&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Width&amp;quot; Value=&amp;quot;300&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Height&amp;quot; Value=&amp;quot;450&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;BorderBrush&amp;quot; Value=&amp;quot;Gray&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Background&amp;quot; Value=&amp;quot;White&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Foreground&amp;quot; Value=&amp;quot;Black&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;BorderThickness&amp;quot; Value=&amp;quot;1&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;CardTemplates&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplateCollection&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource CharacterCardTemplate}&amp;quot; Value=&amp;quot;Ace&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource CharacterCardTemplate}&amp;quot; Value=&amp;quot;King&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource CharacterCardTemplate}&amp;quot; Value=&amp;quot;Queen&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource CharacterCardTemplate}&amp;quot; Value=&amp;quot;Jack&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource TwoTemplate}&amp;quot; Value=&amp;quot;Two&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource ThreeTemplate}&amp;quot; Value=&amp;quot;Three&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource FourTemplate}&amp;quot; Value=&amp;quot;Four&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource FiveTemplate}&amp;quot; Value=&amp;quot;Five&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource SixTemplate}&amp;quot; Value=&amp;quot;Six&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource SevenTemplate}&amp;quot; Value=&amp;quot;Seven&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource EightTemplate}&amp;quot; Value=&amp;quot;Eight&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource NineTemplate}&amp;quot; Value=&amp;quot;Nine&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;local:CardTemplate Template=&amp;quot;{StaticResource TenTemplate}&amp;quot; Value=&amp;quot;Ten&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/local:CardTemplateCollection&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Style.Triggers&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Trigger Property=&amp;quot;IsChecked&amp;quot; Value=&amp;quot;True&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;BorderBrush&amp;quot; Value=&amp;quot;#FF0C1A89&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Background&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;LinearGradientBrush EndPoint=&amp;quot;0.5,1&amp;quot; MappingMode=&amp;quot;RelativeToBoundingBox&amp;quot; StartPoint=&amp;quot;0.5,0&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;GradientStop Color=&amp;quot;#FFF1EDED&amp;quot; Offset=&amp;quot;0&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;GradientStop Color=&amp;quot;White&amp;quot; Offset=&amp;quot;1&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/LinearGradientBrush&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter.Value&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Trigger&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Trigger Property=&amp;quot;CardType&amp;quot; Value=&amp;quot;Diamond&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Foreground&amp;quot; Value=&amp;quot;#FFd40000&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Trigger&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Trigger Property=&amp;quot;CardType&amp;quot; Value=&amp;quot;Heart&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Foreground&amp;quot; Value=&amp;quot;#FFd40000&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Trigger&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Style.Triggers&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;/Style&amp;gt;&lt;/p&gt;  &lt;p align="justify"&gt;Notice all the templates added as CardTemplates values. UpdateTemplate method will assign the right template based on the card value. We also define selected visual state of the PlayingCard using triggers and render a gradient background. We also use triggers to define foreground color of red if card is of type Diamond or Heart. That is all we need to get our PlayingCard working. For demonstration purpose I build a complete deck of cards as a card fan and render it in a circular panel (credit: I took this panel from color swatch sample that ships with Microsoft Expression Blend). Also I bring selected card to the front by setting its Z-Index. &lt;/p&gt; &lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/TFb9wy8BfZI/AAAAAAAAG-8/ZAyhQZff9MM/CardDeck.png" /&gt;   &lt;p&gt;Figure 2 – Complete card deck with 5 of diamond selected (notice selection background gradient)&lt;/p&gt;  &lt;p&gt;Following is the code behind for MainWindow that renders the card deck.&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// Interaction logic for MainWindow.xaml     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public partial class MainWindow : Window     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public MainWindow()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; InitializeComponent(); &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (CardType type in Enum.GetValues(typeof(CardType)))    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (CardValue value in Enum.GetValues(typeof(CardValue)))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PlayingCard card = new PlayingCard();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; card.CardType = type;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; card.CardValue = value;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Deck.Children.Add(card);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Deck.AddHandler(ToggleButton.CheckedEvent, new RoutedEventHandler(OnCardSelected));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private void OnCardSelected(object sender, RoutedEventArgs args)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_selectedCard != null)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _selectedCard.IsChecked = false;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Canvas.SetZIndex(_selectedCard, 0);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _selectedCard = args.OriginalSource as PlayingCard; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_selectedCard != null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _selectedCard.IsChecked = true;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Canvas.SetZIndex(_selectedCard, 1);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PlayingCard _selectedCard;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;h4&gt;Last Words&lt;/h4&gt;  &lt;p align="justify"&gt;I hope I was able to provide some insight into power and simplicity of modeling UI from this example. WPF is very rich and flexible architecture that allows one to perform wonders with things like templates and styles. It could also be fun at the same time and so a very fatal addiction! If you have any comments or suggestions please do not hesitate to leave a note. Thanks !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-2346740582188557357?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/2346740582188557357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=2346740582188557357' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2346740582188557357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2346740582188557357'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2010/08/power-of-templates-in-control.html' title='Power of Templates In Control Development Within Windows Presentation Foundation'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_LOoKjxVTcbc/TFb7DDX8BXI/AAAAAAAAG-4/_m6u0p7iLH4/s72-c/CardImage.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-2317323231419083139</id><published>2010-06-11T20:25:00.001-07:00</published><updated>2010-06-11T20:30:04.625-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Perforce'/><category scheme='http://www.blogger.com/atom/ns#' term='Subversion'/><category scheme='http://www.blogger.com/atom/ns#' term='Source Code Control Systems'/><category scheme='http://www.blogger.com/atom/ns#' term='Mercurial'/><title type='text'>Easy Perforce setup</title><content type='html'>&lt;p&gt;After trying out many source code control systems, I personally found perforce to be the easiest to set up and maintain. Before settling on perforce I tried Mercurial, Subversion, CVS and Microsoft Team Foundation Server (it was so darn complicated that I gave up on it). So here I am sharing these tips / experiences with you to make your Perforce set up experience easier. But before I begin I must mention that I am not a Unix person, but here are common problems I found with these SCC:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;What to use ? – There are so many client and server editions that I don’t know which one to download! On top of that everyone seems to have their own distinct favorite making it hard to choose.&lt;/li&gt;    &lt;li&gt;Hard to install and configure -&amp;#160; If you are lucky to get one of these installed you need additional degree to learn how to configure them up. Mercurial was relatively easy to set up but it was not intuitive for me to add files to the depot.&lt;/li&gt;    &lt;li&gt;Limited (or lack of free) integration with tools – I use visual studio for my development and it is a must for me to use a SCC that integrates with visual studio. No command line or shell support is not good enough.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I found perforce easy to set up and configure. It also is flexible to store depot files and version database at flexible locations. You can configure P4ROOT system variable to indicate to perforce where you want it to store version database (make sure you restart perforce service after setting P4ROOT). To specify where perforce should store files in depot, type p4 depot &amp;lt;depot_name&amp;gt; where depot_name is the name of your depot (default is “depot”). This will bring up notepad configuration for depot where you can specify depot location in the Map: section (you can also use absolute paths but any path relative or absolute must always end with \… so for example D:\Depot\…). I strongly suggest having P4Root same as depot root since it makes it convenient for performing backups. Also perforce client P4V is standard client which integrates with a lot of IDEs including visual studio ! I hope this makes your perforce setup experience smoother !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-2317323231419083139?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/2317323231419083139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=2317323231419083139' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2317323231419083139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2317323231419083139'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2010/06/easy-perforce-setup.html' title='Easy Perforce setup'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-5513686545284581925</id><published>2010-02-17T15:29:00.001-08:00</published><updated>2010-02-17T15:29:53.257-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Localization'/><category scheme='http://www.blogger.com/atom/ns#' term='WeakReference'/><title type='text'>Localization Made Easy In WPF</title><content type='html'>&lt;h4&gt;Background&lt;/h4&gt;  &lt;p&gt;In this blog I will talk about localization in WPF applications. XAML is a great tool for declaratively create application interfaces and we shall use this declarative power to leverage globalization / localization capabilities of .NET. While designing this feature following considerations were paramount:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Localizing applications must be declaratively done in XAML with no code behind &lt;/li&gt;    &lt;li&gt;XAML code must be easy to read and maintain &lt;/li&gt;    &lt;li&gt;Runtime culture change support must be in place so applications need not reboot for culture change to take place (note: this may or may not be a feature you would want) &lt;/li&gt;    &lt;li&gt;Solution must be efficient both in terms of memory and CPU time since operations are performed on UI thread &lt;/li&gt;    &lt;li&gt;Design time experience must not be altered, so developers can develop UI based on default language without worrying about how it is localized at runtime &lt;/li&gt; &lt;/ol&gt;  &lt;h4&gt;&lt;/h4&gt;  &lt;h4&gt;&lt;/h4&gt;  &lt;h4&gt;References&lt;/h4&gt;  &lt;p&gt;I took inspiration / ideas from the following posts:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Force WPF re-binding - &lt;a title="http://beta.blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/07/14/silverlight-quick-tip-how-to-force-re-binding.aspx" href="http://beta.blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/07/14/silverlight-quick-tip-how-to-force-re-binding.aspx"&gt;      &lt;br /&gt;http://beta.blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/07/14/silverlight-quick-tip-how-to-force-re-binding.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Using resource files for localization both in XAML and code &lt;a title="http://windowsclient.net/learn/video.aspx?v=297139" href="http://windowsclient.net/learn/video.aspx?v=297139"&gt;-       &lt;br /&gt;http://windowsclient.net/learn/video.aspx?v=297139&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Weak references in C# -     &lt;br /&gt;&lt;a title="http://www.switchonthecode.com/tutorials/csharp-tutorial-weak-references" href="http://www.switchonthecode.com/tutorials/csharp-tutorial-weak-references"&gt;http://www.switchonthecode.com/tutorials/csharp-tutorial-weak-references&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Code for the article&lt;/h4&gt;  &lt;p&gt;You can download the code for the article here &lt;/p&gt; &lt;iframe title="Preview" style="padding: 0px; width: 98px; height: 115px; background-color: rgb(252, 252, 252);" marginwidth="0" marginheight="0" src="http://cid-a521a90cb40d14ff.skydrive.live.com/embedicon.aspx/BloggerContent/Localization.rar" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;h4&gt;Step 1 – Create Localized Resource Files&lt;/h4&gt;  &lt;p&gt;First step is to create resource files that hold localized resources. I created a WPF application and under Property folder I open Resources.resx and enter a string with key “Hello” and value “Hello”. This is my English resource file. Also what is most important is to pick &lt;strong&gt;Access Modifier as Public&lt;/strong&gt; for this resource file or else XAML will not be able to access it.&lt;/p&gt;  &lt;p&gt;I also created another resource file called Resources.ru-RU.resx and added it to the Property folder. In this resource file I added a string with key “Hello” and value “Здравствуйте” which obviously means hello in Russian. So depending on the culture, application should pick the right string. Also notice that in this resource file, &lt;strong&gt;Access Modifier is set to No code generation&lt;/strong&gt;.&lt;/p&gt;  &lt;h4&gt;Step 2 – Create a simple Window&lt;/h4&gt;  &lt;p&gt;Next we create a simple window with two radio buttons to give the user ability to switch cultures between English and Russian and a text block that would display hello string from the correct resource dictionary. &lt;/p&gt;  &lt;p&gt;To localize a control we need to set an attached property on the control called Localization. This property is of type LocalizationInfo that has two properties to support localization:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Property – This is the actual DependencyProperty that should display localized value on the UI. In our example we use TextBlock.TextProperty for this purpose. &lt;/li&gt;    &lt;li&gt;ResourceKey – This is the resource key within the resource file. In our case this is “Hello”. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Here is the XAML definition of the window:&lt;/p&gt;  &lt;p&gt;&amp;lt;Window x:Class="Localization.Window1"   &lt;br /&gt;    xmlns="&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/a&gt;    &lt;br /&gt;    xmlns:x="&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml%22"&gt;http://schemas.microsoft.com/winfx/2006/xaml"&lt;/a&gt;    &lt;br /&gt;    xmlns:local="clr-namespace:Localization"    &lt;br /&gt;    xmlns:resources="clr-namespace:Localization.Properties"   &lt;br /&gt;    Title="Window1" Height="300" Width="300"&amp;gt;           &lt;br /&gt;    &amp;lt;StackPanel ButtonBase.Click="OnLanguageChanged"&amp;gt;    &lt;br /&gt;        &amp;lt;RadioButton x:Name="EnglishButton" Content="English" IsChecked="True"/&amp;gt;    &lt;br /&gt;        &amp;lt;RadioButton Content="Russian"/&amp;gt;    &lt;br /&gt;        &amp;lt;TextBlock Text="{x:Static resources:Resources.Hello}"&amp;gt;    &lt;br /&gt;            &lt;strong&gt;&amp;lt;local:LocalizationManager.Localization&amp;gt;     &lt;br /&gt;                &amp;lt;local:LocalizationInfo      &lt;br /&gt;                Property="{x:Static TextBlock.TextProperty}"      &lt;br /&gt;                ResourceKey="Hello"/&amp;gt;           &lt;br /&gt;            &amp;lt;/local:LocalizationManager.Localization&amp;gt;&lt;/strong&gt;                               &lt;br /&gt;        &amp;lt;/TextBlock&amp;gt;    &lt;br /&gt;    &amp;lt;/StackPanel&amp;gt;    &lt;br /&gt;&amp;lt;/Window&amp;gt;&lt;/p&gt;  &lt;p&gt;Note in bold the LocalizationInfo property and also design time text support via static Resources.Hello field. Also the radio buttons are hooked via attached handler to OnLanguageChanged method:&lt;/p&gt;  &lt;p&gt;private void OnLanguageChanged(object sender, RoutedEventArgs e)   &lt;br /&gt;{    &lt;br /&gt;    Thread.CurrentThread.CurrentUICulture =    &lt;br /&gt;          new CultureInfo((bool)EnglishButton.IsChecked ? "en-US" : "ru-RU");    &lt;br /&gt;    LocalizationManager.UpdateResources();    &lt;br /&gt;}&lt;/p&gt;  &lt;h4&gt;How does it all work?&lt;/h4&gt;  &lt;p&gt;The magic of keeping track of localizable UI elements and updating their content is done within LocalizationManager class. UpdateResources is the interesting method:&lt;/p&gt;  &lt;p&gt;/// &amp;lt;summary&amp;gt;   &lt;br /&gt;/// Updates the resources after a culture change has occurred    &lt;br /&gt;/// &amp;lt;/summary&amp;gt;    &lt;br /&gt;public static void UpdateResources()    &lt;br /&gt;{    &lt;br /&gt;    List&amp;lt;WeakReference&amp;gt; deadReferences = new List&amp;lt;WeakReference&amp;gt;(); &lt;/p&gt;  &lt;p&gt;    foreach (WeakReference reference in Elements)   &lt;br /&gt;    {    &lt;br /&gt;            FrameworkElement element = reference.Target as FrameworkElement; &lt;/p&gt;  &lt;p&gt;                if (element != null)   &lt;br /&gt;                {    &lt;br /&gt;                    LocalizationInfo localizationInfo = GetLocalization(element);    &lt;br /&gt;                    if (localizationInfo != null)    &lt;br /&gt;                    {    &lt;br /&gt;                        element.SetValue(localizationInfo.Property,    &lt;br /&gt;                                         Resources.ResourceManager.GetString(    &lt;br /&gt;                                            localizationInfo.ResourceKey,    &lt;br /&gt;                                            Thread.CurrentThread.CurrentUICulture));    &lt;br /&gt;                    }    &lt;br /&gt;                }    &lt;br /&gt;                else    &lt;br /&gt;                {    &lt;br /&gt;                    deadReferences.Add(reference);    &lt;br /&gt;                }    &lt;br /&gt;    } &lt;/p&gt;  &lt;p&gt;    foreach (WeakReference reference in deadReferences)   &lt;br /&gt;    {    &lt;br /&gt;                Elements.Remove(reference);    &lt;br /&gt;    }    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;It basically iterates over HashSet of localizable FrameworkElements and updates the content for DependencyProperty from localized resources. Note that we maintain a HashSet of weak references so UI elements can still be garbage collected without us holding references. As a cleanup phase we detect the dead references and remove them from the HashSet. That’s it now you know how to localize your WPF applications with minimal code !&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-5513686545284581925?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/5513686545284581925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=5513686545284581925' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5513686545284581925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5513686545284581925'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2010/02/localization-made-easy-in-wpf.html' title='Localization Made Easy In WPF'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-2922156037839083323</id><published>2009-08-07T20:26:00.001-07:00</published><updated>2009-08-07T21:13:57.948-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Button'/><category scheme='http://www.blogger.com/atom/ns#' term='Photoshop'/><category scheme='http://www.blogger.com/atom/ns#' term='Paths'/><category scheme='http://www.blogger.com/atom/ns#' term='Rounded rectangle'/><category scheme='http://www.blogger.com/atom/ns#' term='Icon'/><category scheme='http://www.blogger.com/atom/ns#' term='Vector mask'/><category scheme='http://www.blogger.com/atom/ns#' term='Web 2.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Photoshop Styles and Gradients'/><category scheme='http://www.blogger.com/atom/ns#' term='Cross'/><category scheme='http://www.blogger.com/atom/ns#' term='Pen tool'/><title type='text'>How to make a perfect Web 2.0 close button using Photoshop CS4</title><content type='html'>&lt;h4&gt;Background&lt;/h4&gt;  &lt;p&gt;In this tutorial I will explain how to create a Web 2.0 style close button with a perfect cross on it. We shall be creating this button using Adobe Photoshop CS4. Before we get started, this is how the end product will look like:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh6.ggpht.com/_LOoKjxVTcbc/SnzaIMixdAI/AAAAAAAAGng/i2tiScRrATU/1.png" /&gt; &lt;/p&gt;  &lt;p&gt;Note, all the transient images of sample are displayed in 300% zoom mode.&lt;/p&gt;  &lt;h4&gt;Step 1&lt;/h4&gt;  &lt;p&gt;The first step in creating the button is to create the cross image. For this purpose we shall create a new 128 pixel by 128 pixel Photoshop document having a resolution of 72 pixels per inch. You would ask why did we create 128 pixel by 128 pixel document? The answer is twofold. First, 128 x 128 pixel image is a standard icon size in many application (so is 16 x 16, 24 x 24, 48 x 48, 80 x 80, 256 x 256) hence by choosing these dimensions you would get the icon in the standard size. Secondly, in Photoshop the grid size is 8 pixels side square. Hence if you are indulging in creating a high precision image using pens, it is easier to snap points to grid.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/Snzb-SqJMBI/AAAAAAAAGnk/IBvA53YUxn4/2.png" /&gt; &lt;/p&gt;  &lt;h4&gt;Step 2&lt;/h4&gt;  &lt;p&gt;A cross is really a plus sign rotated by an angle of 45 degrees. Hence we shall first create a plus sign. Rename the background layer as Vertical_Bar as this is the layer we shall be creating our vertical bar on. Select the pen tool and zoom the image to 300% for high precision path drawing. Now click the first pen path vertex one row down from top and at the end of sixth square from left. Click to create second vertex at the horizontal distance of 4 squares from the first vertex. Now click on third vertex vertically below the second one in the second last row. Lastly click on the first vertex to obtain a closed path in the shape of vertical bar.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/SnzeNf2FMqI/AAAAAAAAGno/8I4U0JoohB0/3.png" /&gt; &lt;/p&gt;  &lt;p&gt;As you can see the vertical path is symmetrically placed in the document. Now choose Layer-&amp;gt;Vector Mask-&amp;gt; Current Path. This will create a vector path corresponding to the path we have drawn. Vector paths are important since in Photoshop all image manipulation by default are pixel based. If vector paths / masks are used then image can be enlarged, shrink, rotated without any loss of quality since in this case vector components of path are manipulated and no pixel interpolation / extrapolation is done. Now select a foreground color (I chose #e5dcdc) and selecting the layer choose Edit-&amp;gt;Fill to fill the layer with foreground color. You will see since we have applied a vector mask, only the portion of image inside the closed path will be filled with the color leaving outside area transparent as before.&lt;/p&gt;  &lt;p&gt;Create a new layer and name it Horizontal Path. Repeat the above creating a horizontal bar this time and proceed to create vector mask and fill the masked layer with the same color. Now you should obtain a plus sign.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/SnzgojZMoSI/AAAAAAAAGns/GZ__CxdhM_4/4.png" /&gt; &lt;/p&gt;  &lt;h4&gt;Step 3&lt;/h4&gt;  &lt;p&gt;Click on Vertical_Bar layer and go to Paths tab. Click on the vertical path. This should draw a solid border around the vertical path. Go back and select Vertical_Bar layer mask. Now press Ctrl + T to enter the transformation mode. In the top transformation toolbar, enter 45 in the angle textbox to rotate the layer mask by 45 degrees. Now press enter key to exit the transformation mode. Repeat the same steps for Horizontal_Bar layer.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh5.ggpht.com/_LOoKjxVTcbc/SnzlDn4G-AI/AAAAAAAAGnw/LMThqulnzw8/5.png" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/Snzl2ZTp6DI/AAAAAAAAGn0/OG3FBZrF_N4/6.png" /&gt; &lt;/p&gt;  &lt;p&gt;We are done with making a perfect cross icon and ready to proceed to create the button on which this icon will be overlaid. This cross can be reused in other UI elements as well so we will save this in cross.psd file for later reuse.&lt;/p&gt;  &lt;h4&gt;Step 4&lt;/h4&gt;  &lt;p&gt;To create a fancy Web 2.0 style background we shall reuse some Photoshop styles and gradients that can help us quickly set the effects we want. I recommend downloading these styles from &lt;a title="http://myphotoshopbrushes.com/styles_and_gradients" href="http://myphotoshopbrushes.com/styles_and_gradients"&gt;http://myphotoshopbrushes.com/styles_and_gradients&lt;/a&gt;. I personally downloaded &lt;a href="http://myphotoshopbrushes.com/styles_and_gradients/id/3013" target="_blank"&gt;42 Button Layer Styles&lt;/a&gt; and &lt;a href="http://myphotoshopbrushes.com/styles_and_gradients/id/3016" target="_blank"&gt;Ultimate Web 2.0 Styles&lt;/a&gt; from the parent link. Once you download the files, open the zip file and double click on .asl file. This will register the styles automatically with Photoshop.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh5.ggpht.com/_LOoKjxVTcbc/Snzqp_JFmvI/AAAAAAAAGn4/tpiY0fRrr5E/7.png" /&gt; &lt;/p&gt;  &lt;h4&gt;Step 5&lt;/h4&gt;  &lt;p&gt;Now create a 144 pixel by 144 pixel image in Photoshop. Name the layer button. Click and hold mouse on rectangle tool in Photoshop toolbox. This will pop down all the shapes from the toolbox. Select rounded rectangle from the dropdown. Ensure that path option is selected on the top toolbox. This will ensure that any shape that is drawn is considered a closed path. Select the radius to be 10px.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/SnzsbN62vLI/AAAAAAAAGoE/PGHzo5q5qSA/8.png" /&gt; &lt;/p&gt;  &lt;p&gt;Now draw a rounded rectangle having one row border outside the rectangle. Again choose Layer-&amp;gt;Vector Mask-&amp;gt; Current Path to create a vector mask on the layer. Now select the selection tool and select any style from the styles palette with layer selected(I selected Photobucket Join style for background).&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh5.ggpht.com/_LOoKjxVTcbc/SnzuJO6QAiI/AAAAAAAAGoI/Yn_94_2hUd8/9.png" /&gt; &lt;/p&gt;  &lt;h4&gt;Step 6&lt;/h4&gt;  &lt;p&gt;Now goto cross.psd and press Ctrl + D to select the entire image. Next, choose Edit-&amp;gt;Copy Merged to copy the merged layer. Go back to the button document now and press Ctrl + V to paste the cross on top of the button layer. Now select this new layer and name it cross. With cross layer selected, select any style from the style palette to fill the cross with desired gradient (I selected Flixster Search style). There you go, now you have a trendy and crispy Web 2.0 style cross button.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/Snzv15bzofI/AAAAAAAAGoM/GJHVjcavs-4/10.png" /&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-2922156037839083323?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/2922156037839083323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=2922156037839083323' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2922156037839083323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2922156037839083323'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2009/08/how-to-make-perfect-web-20-close-button.html' title='How to make a perfect Web 2.0 close button using Photoshop CS4'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_LOoKjxVTcbc/SnzaIMixdAI/AAAAAAAAGng/i2tiScRrATU/s72-c/1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-5889116027473767095</id><published>2009-07-20T20:27:00.001-07:00</published><updated>2009-07-20T20:32:52.970-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Http Handlers'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET AJAX'/><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET MVC'/><category scheme='http://www.blogger.com/atom/ns#' term='AjaxPro'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><category scheme='http://www.blogger.com/atom/ns#' term='jQuery'/><title type='text'>Simple &amp; Practical introduction to Asynchronous JavaScript And XML (AJAX)</title><content type='html'>&lt;h4&gt;&lt;/h4&gt;  &lt;h4&gt;Background&lt;/h4&gt;  &lt;p&gt;Asynchronous JavaScript and XML or AJAX has been the revolutionary technology that enabled rich user experience over the web, much like desktop rich user experience. In this series, I will describe my journey of learning AJAX and some simple steps that will get you started with this simple but powerful technology.&lt;/p&gt;  &lt;h4&gt;Introduction&lt;/h4&gt;  &lt;p&gt;AJAX enables web developers dynamically update a web page via background asynchronous posts to the server. Hence it removes the necessity of sending entire page back to the server and cause&amp;#160; global refresh in the browser. This results in following major benefits:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Rich user experience – a web user doesn’t have to wait until the entire page is loaded. Nor is he / she is distracted by visual information loss during the page reloads. AJAX also can be used to display progress information while a sub-portion of the page is being updated / loaded from the server. &lt;/li&gt;    &lt;li&gt;Server scalability – Since only minimal information is exchanged between the client and the server, hence server can serve more clients in turn with the same amount of resources (memory, CPU). This helps in increasing server scalability. &lt;/li&gt;    &lt;li&gt;Client efficiency – The client browser only needs to update a sub-portion of already loaded web page as opposed to parsing and displaying the entire page all over again. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;img src="http://lh4.ggpht.com/_LOoKjxVTcbc/SmHdoM02RnI/AAAAAAAAGlU/4G0FFrdqj2k/ClassicWebApp.gif" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 1 – Classic Web Application Model&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh5.ggpht.com/_LOoKjxVTcbc/SmHdoDkvX5I/AAAAAAAAGlY/RSkGpM79Ybw/AjaxWebApp.gif" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 2 – AJAX Web Application Model&lt;/p&gt;  &lt;p&gt;The solid lines depict synchronous operations whereas the gray lines depict asynchronous operations.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h4&gt;Building Blocks of AJAX&lt;/h4&gt;  &lt;p&gt;AJAX is not a technology by itself. It is an outcome of several collaborating technologies that fit their respective roles in the overall end to end asynchronous HTTP request / response process. The major building blocks involved in AJAX web application model are as follows:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Standards based presentation using XHTML and CSS. &lt;/li&gt;    &lt;li&gt;DHTML – Browser capabilities to manipulate XML Document Object Model (DOM) for the loaded web page. &lt;/li&gt;    &lt;li&gt;JavaScript – Base language technology for performing all client side activities during AJAX operations. Client browser must have support for JavaScript in order to support AJAX operations. Many vendors have to support both AJAX style web pages (for desktop browsers) as well as traditional post-back web pages (for mobile device browsers) to capture the entire spectrum of users. &lt;/li&gt;    &lt;li&gt;XMLHttpRequest object – A browser must support XMLHttpRequest JavaScript object for initiating asynchronous web requests. Different browsers have different ways to retrieve this object. There are many documented shims available that explain how to retrieve this object. Here is an example from &lt;a href="http://en.wikipedia.org/wiki/XMLHttpRequest"&gt;wikipedia&lt;/a&gt;:       &lt;p&gt;// Provide the XMLHttpRequest class for IE 5.x-6.x:        &lt;br /&gt;// Other browsers (including IE 7.x-8.x) ignore this         &lt;br /&gt;// when XMLHttpRequest is predefined         &lt;br /&gt;if (typeof(XMLHttpRequest) == &amp;quot;undefined&amp;quot;) {         &lt;br /&gt;&amp;#160; XMLHttpRequest = function()&amp;#160;&amp;#160; {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Msxml2.XMLHTTP.6.0&amp;quot;); }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Msxml2.XMLHTTP.3.0&amp;quot;); }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Msxml2.XMLHTTP&amp;quot;); }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;); }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; throw new Error(&amp;quot;This browser does not support XMLHttpRequest.&amp;quot;);         &lt;br /&gt;&amp;#160; };         &lt;br /&gt;} &lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This example&amp;#160; shows how to add a shim type of the same name XMLHttpRequest if the browser doesn’t support it out of the box. For a complete reference on XMLHttpRequest JavaScript class, refer to &lt;a href="https://developer.mozilla.org/en/XMLHttpRequest"&gt;Mozilla Developer Center page&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I highly recommend reading a book that explains the above technologies in depth to get your basics right. I personally read &lt;a href="http://www.amazon.com/Beginning-Ajax-ASP-NET-Wallace-McClure/dp/047178544X/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1247929864&amp;amp;sr=8-1"&gt;Beginning Ajax with ASP.NET&lt;/a&gt; and found it a very good start for beginners. However later chapters in the book are outdated as technologies that they mention especially Microsoft Atlas have considerably changed since the book was released.&lt;/p&gt;  &lt;h4&gt;First AJAX Experience&lt;/h4&gt;  &lt;p&gt;In the beginning of this blog I promised you to present AJAX in a very approachable style. For years I had ignored learning this technology as I considered it to be very non-standard and hacky then. Now I differ in my opinion owing to the fact that there are many technologies in the AJAX web model that have been recognized as industry standards and are now W3C compliant. Anyways let’s now see things in action ! Create an ASP.NET web application in Visual Studio where you will test your first AJAX code. Then create an XML file note.xml in the project and overwrite its content with the following:&lt;/p&gt;  &lt;p&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;iso-8859-1&amp;quot;?&amp;gt;    &lt;br /&gt;&amp;lt;note&amp;gt;     &lt;br /&gt;&amp;lt;to&amp;gt;Tove&amp;lt;/to&amp;gt;     &lt;br /&gt;&amp;lt;from&amp;gt;Jani&amp;lt;/from&amp;gt;     &lt;br /&gt;&amp;lt;heading&amp;gt;Reminder&amp;lt;/heading&amp;gt;     &lt;br /&gt;&amp;lt;body&amp;gt;Don't forget me this weekend!&amp;lt;/body&amp;gt;     &lt;br /&gt;&amp;lt;/note&amp;gt;&lt;/p&gt;  &lt;p&gt;Next create a html document in the project ajax.htm with the following content:&lt;/p&gt;  &lt;p&gt;&amp;lt;html&amp;gt;    &lt;br /&gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;First AJAX Example&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;     &lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var request;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var READYSTATE_COMPLETE = 4;&amp;#160;&amp;#160; // Indicates completion state of XMLHttpRequest object     &lt;br /&gt;&lt;/p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Provide the XMLHttpRequest class for IE 5.x-6.x:   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Other browsers (including IE 7.x-8.x) ignore this   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // when XMLHttpRequest is predefined   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (typeof(XMLHttpRequest) == &amp;quot;undefined&amp;quot;) {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; XMLHttpRequest = function()&amp;#160;&amp;#160; {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Msxml2.XMLHTTP.6.0&amp;quot;); }   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Msxml2.XMLHTTP.3.0&amp;quot;); }   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Msxml2.XMLHTTP&amp;quot;); }   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try { return new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;); }   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(e) {}   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new Error(&amp;quot;This browser does not support XMLHttpRequest.&amp;quot;);   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; };&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&amp;#160; &lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; function ReadXmlFile() {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Create XMLHttpRequest object   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; request = new XMLHttpRequest();   &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Open an XML file    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; request.open('GET', 'note.xml', true); &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Attach completion handler to the request    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; request.onreadystatechange = DisplayXmlFile; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Send async request to the server with null context    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; request.send(null);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; function DisplayXmlFile() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // If request is complete, show the content of response in the xmlSpan span     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (request.readyState == READYSTATE_COMPLETE) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; xmlSpan.innerText = request.responseText;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;body&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;span id=&amp;quot;xmlSpan&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; onclick=&amp;quot;ReadXmlFile();&amp;quot; value=&amp;quot;ReadXml&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;lt;/body&amp;gt;     &lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;  &lt;p&gt;Finally fire the app in the browser and open ajax.htm. You will see if you hit the ReadXml button, the xmlSpan span gets populated with the content of note.xml without refreshing the page as shown in Figure 3 below.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh4.ggpht.com/_LOoKjxVTcbc/SmHx17q_KdI/AAAAAAAAGmE/vXRBjJxNlUQ/FirstAjaxExample.gif" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 3 – Running the first AJAX example&lt;/p&gt;  &lt;h4&gt;Security Note&lt;/h4&gt;  &lt;p&gt;In order to ensure online security and prevent cross scripting attacks, the browsers limit the XMLHttpRequest object to only request resources from the same domain as the domain of the web application. You can verify this in the above example. Instead of requesting note.xml, try requesting &lt;a title="http://www.w3schools.com/XML/note.xml" href="http://www.w3schools.com/XML/note.xml"&gt;http://www.w3schools.com/XML/note.xml&lt;/a&gt; which has the same content. Running the application will not allow the xml file to be fetched. Replace it again with note.xml and it will work again.&lt;/p&gt;  &lt;h4&gt;AJAX Frameworks&lt;/h4&gt;  &lt;p&gt;In recent years, the use of AJAX in major web portals have revolutionized online user experience. Although Microsoft was the first company to make use of AJAX, it was Google which truly captured the power of this technology and set a new standard for online user experience. Several frameworks have been built to increase developer productivity while developing AJAX based web applications. These frameworks can be categorized into following major categories:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Client side frameworks – JavaScript libraries/frameworks that help developers reuse/leverage client side JavaScript code. &lt;/li&gt;    &lt;li&gt;Server side frameworks – Server side code generators/injectors combined with capabilities to extend client side AJAX JavaScript code to achieve extensibility and reusability in AJAX web application development. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Each of the following categories have their own benefits and drawbacks. The decision to pick one over the other depends in the nature of application being developed and platforms being used to develop those applications. A lot of time developers also pick a combination of tools belonging to different categories and integrate them together to achieve the desired end product. I will walk you through an example of each of the following categories in the upcoming sections.&lt;/p&gt;  &lt;h4&gt;Client Side Frameworks&lt;/h4&gt;  &lt;p&gt;Many efforts have been made to enhance JavaScript to support AJAX via reusable libraries. Quite possibly the biggest effort is the conception of &lt;a href="http://www.jquery.com"&gt;jQuery&lt;/a&gt; – a lightweight library that emphasizes interaction between JavaScript and HTML.&amp;#160; Microsoft has already adopted this framework which is now shipping with &lt;a href="http://www.asp.net/mvc/"&gt;ASP.NET MVC Framework&lt;/a&gt; and in the near future will be a part of upcoming Visual Studio 2010 release. Let us rewrite our previous example using jQuery. Again follow the previous example as is except this time your html page should have the following content:&lt;/p&gt;  &lt;p&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;&lt;a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&lt;/a&gt;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;html xmlns=&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml&amp;quot;"&gt;http://www.w3.org/1999/xhtml&amp;quot;&lt;/a&gt;&amp;gt;     &lt;br /&gt;&amp;lt;head&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;title&amp;gt;AJAX with jQuery&amp;lt;/title&amp;gt;     &lt;br /&gt;&amp;lt;/head&amp;gt;     &lt;br /&gt;&amp;lt;script src=&amp;quot;Scripts/jquery-1.3.2.js&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $(document).ready(function() { &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(&amp;quot;#ReadButton&amp;quot;).click(function() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $.ajax({     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; type: &amp;quot;GET&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; url: &amp;quot;note.xml&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; success: function(msg) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(&amp;quot;#xmlSpan&amp;quot;).attr(&amp;quot;innerText&amp;quot;, msg.xml);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; });&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;body&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;span id=&amp;quot;xmlSpan&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; id=&amp;quot;ReadButton&amp;quot; value=&amp;quot;ReadXml&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;lt;/body&amp;gt;     &lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;  &lt;p&gt;The script to fetch note.xml this time is so much more concise! Also note that we didn’t need to do anything funky on the server side to make it work. We didn’t had to create XMLHttpRequest object and check for browser type while doing so. Also we didn’t had to declare constants to check states for XMLHttpRequest object. Just a precise subscription to success event got our callback going!&lt;/p&gt;  &lt;p&gt;Ok you must be wondering well, the above works well but what if HTTP POST is required instead of a GET and how does one go about executing business logic on the backend while making asynchronous HTTP POST requests. Well the answer is simple. We can use POST version of jQuery AJAX call to achieve the same. We shall see this approach in the scenario below.&lt;/p&gt;  &lt;p&gt;Consider that you want to call a method GetPerson on your backend ASP.NET page that gives you a custom Person object. Let’s assume that this Person object is to be processed on the client and displayed to the user. Let’s see how we can go about doing it. &lt;/p&gt;  &lt;p&gt;In order to achieve the above scenario we must understand how serialization works between a backend .NET managed object and JavaScript objects. Any object in JavaScript can be serialized to &lt;a href="http://www.json.com/"&gt;JSON&lt;/a&gt; (JavaScript Object Notation) format. As well as any JSON object can be deserialized into a JavaScript object. JSON is really a format for structured data interchange between systems. The BNF for object denotation in JSON is as follows:     &lt;br /&gt;    &lt;br /&gt;JSON Notation := { } | {KeyValuePair}     &lt;br /&gt;KeyValuePair&amp;#160;&amp;#160; := Key : Value | KeyValuePair, Key : Value     &lt;br /&gt;Key&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; := String     &lt;br /&gt;Value&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; := String | Number | JSON Notation | Array | true | false | null     &lt;br /&gt;Array&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; := [ ] | [Value] | [Value, Value]&lt;/p&gt;  &lt;p&gt;Hence if you have a person object storing FirstName and LastName then following can be a JSON representation of a Person instance:    &lt;br /&gt;{PersonInstance: {FirstName:John, LastName:Rambo}}     &lt;br /&gt;and an array of Person objects can be represented as :     &lt;br /&gt;{PersonList: [{FirstName:John, LastName:Rambo}, {FirstName:Austin, LastName:Powers}]}&lt;/p&gt;  &lt;p&gt;The format of JSON closely matches how JavaScript interprets its objects, i.e. in the form of nested key value pairs. Yes, everything in JavaScript, properties, methods, events are just key value pairs of some sort and hence JavaScript objects are nothing but nested dictionaries! If you follow the persistence format of many other vendors this is usually a strikingly common way of representing objects (Apple also uses a similar plist format to store property lists in MacOS and also in iTunes ! For more information about plist, check out its &lt;a href="http://en.wikipedia.org/wiki/Property_list"&gt;wikipedia&lt;/a&gt; page).&lt;/p&gt;  &lt;p&gt;Anyhow now back to our GetPerson example. We will create a simple ASP.NET page with the following code behind:&lt;/p&gt;  &lt;p&gt;using System;    &lt;br /&gt;using System.Web.Services; &lt;/p&gt;  &lt;p&gt;[Serializable]    &lt;br /&gt;public class Person     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string FirstName {get;set;}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string LastName {get;set;}     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;public partial class Person_Page : System.Web.UI.Page    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; protected void Page_Load(object sender, EventArgs e)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; [WebMethod]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public static Person GetPerson(Person person)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return new Person { FirstName = person.FirstName, LastName = person.LastName };     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;There is one static web method called GetPerson that accepts a parameter of type Person. Person really contains the first name and the last name of a person. GetPerson then simply returns a new Person object with the same first and last name. One important thing to note is that Person object is marked with a Serializable attribute. In CLR if an object is marked with a Serializable attribute then it can be serialized into any given format / and or built from any format back as an object. Also note the public static visibility type and WebMethod attribute on GetPerson method. This is essential to expose a method to be called by client web requests. We shall see how we can call this method from the client code below.&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;Person_Page.aspx.cs&amp;quot; Inherits=&amp;quot;Person_Page&amp;quot; %&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;&lt;a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&lt;/a&gt;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;html xmlns=&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml&amp;quot;"&gt;http://www.w3.org/1999/xhtml&amp;quot;&lt;/a&gt;&amp;gt;     &lt;br /&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;title&amp;gt;jQuery POST Example&amp;lt;/title&amp;gt;     &lt;br /&gt;&amp;lt;/head&amp;gt;     &lt;br /&gt;&amp;lt;script src=&amp;quot;Scripts/jquery-1.3.2.js&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; $(document).ready(function() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(&amp;quot;#GetPerson&amp;quot;).click(function() { &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var firstname = $(&amp;quot;#txtFirstName&amp;quot;).val();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var lastname = $(&amp;quot;#txtLastName&amp;quot;).val();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; content = &amp;quot;{'person':{'FirstName':'&amp;quot; + firstname + &amp;quot;', 'LastName':'&amp;quot; + lastname + &amp;quot;'}}&amp;quot;; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $.ajax({    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; type: &amp;quot;POST&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; url: &amp;quot;Person_Page.aspx/GetPerson&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; data: content,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; contentType: &amp;quot;application/json; charset=utf-8&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; dataType: &amp;quot;json&amp;quot;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; success: function(msg) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var fullName = msg.d.LastName + &amp;quot;, &amp;quot; + msg.d.FirstName;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(&amp;quot;#lblFullName&amp;quot;).text(fullName);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; });&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;body&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;div&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; First Name: &amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;txtFirstName&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Last Name: &amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;txtLastName&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;br /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;input type=&amp;quot;button&amp;quot; id=&amp;quot;GetPerson&amp;quot; value=&amp;quot;GetPerson&amp;quot;&amp;gt;&amp;lt;/input&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;span id = &amp;quot;lblFullName&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/div&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/form&amp;gt;     &lt;br /&gt;&amp;lt;/body&amp;gt;     &lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;  &lt;p&gt;We have two text fields here txtFirstName and txtLastName that capture first and the last name of the person respectively. Then we have a GetPerson button that makes the AJAX call to the code behind of the page and tries to call a web method GetPerson and passes in the constructed JSON from txtFirstName and txtLastName fields via content string variable. Once the response is received back from the server, the text of the span lblFullName is updated to show the full name in the format LastName, FirstName. Following is the screenshot while running the above code:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh3.ggpht.com/_LOoKjxVTcbc/SmM4MNmP25I/AAAAAAAAGmI/EEQE-2DAWoM/jQueryPostExample.gif" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 4 – jQuery POST Example in action&lt;/p&gt;  &lt;p&gt;As can be seen when the CLR receives the POST requests, it queries the HTTP ContentType field value. Since it is specified as application / json, hence it deserializes the person object from JSON to actual Person instance and also serializes the resulting Person object from GetPerson back to JSON. Also notice the JSON string construction from client script in content string object. We specify the key of the object to be ‘person’ which is the same name as the formal parameter name of Person object in GetPerson web method. This allows for binding of parameters during the call so value can be passed correctly to the web method. &lt;/p&gt;  &lt;h4&gt;Server Side Frameworks&lt;/h4&gt;  &lt;p&gt;Server side frameworks dynamically generate and inject AJAX JavaScript snippets into server processed forms, so developers are not bothered writing JavaScript every time they desire AJAX style functionality in their web applications. We already have seen above that JSON and JavaScript correspond quite well to each other and one can be projected to another and vice versa. Armed with this fact, server side frameworks generate proxy JavaScript objects on the fly that correspond with backend data structures. They also inject code that call backend methods asynchronously and pass proxies to and from client browser.&lt;/p&gt;  &lt;p&gt;There are many popular sever side AJAX frameworks such as &lt;a href="http://www.asp.net/ajax/"&gt;Microsoft ASP.NET AJAX&lt;/a&gt;, &lt;a href="http://www.ajaxpro.info/"&gt;AjaxPro&lt;/a&gt;, &lt;a href="http://www.comfortasp.de/"&gt;ComfortASP.NET&lt;/a&gt; and &lt;a href="http://sourceforge.net/projects/magicajax/"&gt;MagicAjax.NET&lt;/a&gt;. In addition, Microsoft has started a community effort to build more server side controls to bring web experience closer to desktop experience via a community project called &lt;a href="http://www.asp.net/ajax/ajaxcontroltoolkit/samples/"&gt;ASP.NET AJAX Control Toolkit&lt;/a&gt; (although last time I checked there were quite a few bugs in this toolkit and some controls such as AutoComplete were completely broken). I must also mention that Microsoft ASP.NET AJAX server framework also contain a client side JavaScript library called Microsoft AJAX library (talk about confusing names) that closely mimics much of OO features present in managed languages such as inheritance, interfaces etc. Microsoft AJAX library can be downloaded from &lt;a title="http://www.asp.net/ajax/downloads/" href="http://www.asp.net/ajax/downloads/"&gt;http://www.asp.net/ajax/downloads/&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;However one must realize serious implications of using various server side frameworks in code. Most of the time these limitations are not very well documented. One common limitation is the use of conflicting HTTP handlers and HTTP modules in ASP.NET projects. HTTP modules and handlers are HTTP request handlers that get executed way before ASP.NET gets to the requests in the application pipeline. Server side frameworks usually utilize these components to inject code into HTML response via JavaScript tags. However if there are more than one server frameworks used (maybe for different purposes than AJAX) than they might conflict and suppress functionality offered by other frameworks by ‘stealing’ the HTTP requests first.&lt;/p&gt;  &lt;p&gt;Another major limitation of server side frameworks is the way they perform asynchronous HTTP requests. ASP.NET AJAX framework for example relies heavily on ASP.NET ViewState object. Hence it is impossible to issue requests from web user controls (commonly known as partial views or *.ascx) using this framework. It is also not compatible with &lt;a href="http://www.asp.net/mvc/"&gt;ASP.NET MVC&lt;/a&gt; framework. Hence it is important to perform background study of a framework and ensure that it is compatible with existing frameworks being used in your web applications.&lt;/p&gt;  &lt;p&gt;Let us see an example of using server side framework. For the purpose of this example I will use AjaxPro framework. You can download AjaxPro framework for free from its &lt;a href="http://www.ajaxpro.info/"&gt;website&lt;/a&gt;. To use this framework, create an ASP.NET web application and simply reference the downloaded assembly (AjaxPro.dll or AjaxPro2.dll depending on the version you download from the website) from your project.&lt;/p&gt;  &lt;p&gt;Next add the following lines in web.config (note: if you already have a httpHandlers section just add the ‘add’ tag from below)&lt;/p&gt;  &lt;p&gt;&amp;lt;httpHandlers&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;add verb=&amp;quot;POST,GET&amp;quot; path=&amp;quot;ajaxpro/*.ashx&amp;quot; type=&amp;quot;AjaxPro.AjaxHandlerFactory,AjaxPro.2&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;lt;/httpHandlers&amp;gt;&lt;/p&gt;  &lt;p&gt;The code above implies that whatever request POST/GET is received for a resource with extension ashx within the ajaxpro folder must be forwarded to AjaxPro.AjaxHandlerFactory http handler defined in AjaxPro.2.dll assembly.&lt;/p&gt;  &lt;p&gt;Next, we will add a new ASP.NET page named AjaxPro_Page to the project. The first thing we need to do in order to hook up this page to AjaxPro http handler is to register it with AjaxPro. We do this via AjaxPro.Utility.RegisterTypeForAjax call from within page’s Page_Load method as follows:&lt;/p&gt;  &lt;p&gt;protected void Page_Load(object sender, EventArgs e)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxPro_Page));     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;The next step is to define method(s) on this page that will be called from within this page by the client code. For the purpose of this example we shall define a GetTime method that will return server time to the client. It is important to mark this method with AjaxMethod attribute so a “proxy” code for this method can be generated by the AjaxPro framework. Following is the definition of GetTime method:&lt;/p&gt;  &lt;p&gt;[AjaxMethod]    &lt;br /&gt;public DateTime GetTime()     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return DateTime.Now;     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;At this time the server part of the code is complete. The complete class should look like as follows:&lt;/p&gt;  &lt;p&gt;using System;    &lt;br /&gt;using AjaxPro; &lt;/p&gt;  &lt;p&gt;public partial class AjaxPro_Page : System.Web.UI.Page    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; protected void Page_Load(object sender, EventArgs e)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxPro_Page));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [AjaxMethod]     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public DateTime GetTime()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return DateTime.Now;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Let us run this page in browser and see what gets generated on the client side. Run this page in browser and view the source for this page. You will find following three script tags that were injected by AjaxPro.AjaxHandlerFactory http handler that we registered in web.config before:&lt;/p&gt;  &lt;p&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/blogtest/ajaxpro/prototype.ashx&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;    &lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/blogtest/ajaxpro/core.ashx&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/blogtest/ajaxpro/converter.ashx&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/blogtest/ajaxpro/AjaxPro_Page,App_Web_hghu6cj1.ashx&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/p&gt;  &lt;p&gt;The first script is basically the code that enables OO concepts such as inheritance and virtual functions used within the code generated by AjaxPro in later stages. Hence it defines the base prototype from which all the AjaxPro client code inherits from. The second script generates core related to IFrame, request queues and general request / response logic. Third script is basically the JSON serializer / deserializer for complex .NET types such as System.Collections.Specialized.NameValueCollection, System.Data.DataSet, System.Data.DataTableDataTable, ProfileBaseConverter and IDictionaryConverter. This enables you to use this complex data types as return types for your .NET methods and use them seamlessly from AjaxPro generated proxy code.&lt;/p&gt;  &lt;p&gt;The last script corresponds to the proxy generated for your code behind. Note that the exact ending of the App_Web_*.ashx handler is random and may not end with hghu6cj1 as in my case. If you navigate to that url and view the source for the code, you will find something similar to the code below:&lt;/p&gt;  &lt;p&gt;AjaxPro_Page_class = function() {};    &lt;br /&gt;Object.extend(AjaxPro_Page_class.prototype, Object.extend(new AjaxPro.AjaxClass(), {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; GetTime: function() {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return this.invoke(&amp;quot;GetTime&amp;quot;, {}, this.GetTime.getArguments().slice(0));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; },     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; url: '/blogtest/ajaxpro/AjaxPro_Page,App_Web_hghu6cj1.ashx'     &lt;br /&gt;}));     &lt;br /&gt;AjaxPro_Page = new AjaxPro_Page_class(); &lt;/p&gt;  &lt;p&gt;Here we can clearly see that AjaxPro generates a JavaScript class named AjaxPro_Page_class and defines invoke code for GetTime method. What it does exactly is define a class AjaxPro_Page_class as an empty class and then add GetTime method to its prototype. This way any instance of this class or its subclass will have access to the GetTime method via prototype chaining. Finally it declares an instance of AjaxPro_Page_class named AjaxPro_Page (same name as our server code behind class) so it can be used from our scripts to invoke methods on the code behind.&lt;/p&gt;  &lt;p&gt;Now we need to hook up the client code to call this GetTime method from AjaxPro_Page. Well its simple. Just replace the code in your AjaxPro_Page.aspx with the following:&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;AjaxPro_Page.aspx.cs&amp;quot; Inherits=&amp;quot;AjaxPro_Page&amp;quot; %&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;&lt;a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&lt;/a&gt;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;html xmlns=&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml&amp;quot;"&gt;http://www.w3.org/1999/xhtml&amp;quot;&lt;/a&gt;&amp;gt;     &lt;br /&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;title&amp;gt;AjaxPro Example&amp;lt;/title&amp;gt;     &lt;br /&gt;&amp;lt;/head&amp;gt;     &lt;br /&gt;&amp;lt;script src=&amp;quot;Scripts/jquery-1.3.2.js&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $(document).ready(function() {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(&amp;quot;#cmdServerTime&amp;quot;).click(function() {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AjaxPro_Page.GetTime(function(result) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(&amp;quot;#lblServerTime&amp;quot;).text(result.value.toString());     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; });     &lt;br /&gt;&amp;lt;/script&amp;gt;     &lt;br /&gt;&amp;lt;body&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;div&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Server Time: &amp;lt;span id=&amp;quot;lblServerTime&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;input type=&amp;quot;button&amp;quot; id=&amp;quot;cmdServerTime&amp;quot; value=&amp;quot;GetServerTime&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/div&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/form&amp;gt;     &lt;br /&gt;&amp;lt;/body&amp;gt;     &lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;  &lt;p&gt;This code basically declares a span with id lblServerTime and a button with id cmdServerTime. In the page load jQuery, it hooks up the click event of cmdServerTime to call AjaxPro_Page.GetTime method, which in turn is hooked up to the anonymous method that replaces the text for the span with the server returned time value from GetTime method. Run it and you shall see the results similar to below screenshot:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://lh6.ggpht.com/_LOoKjxVTcbc/SmUwTs7q22I/AAAAAAAAGmM/gBC2hVHflDM/AjaxProExample.gif" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 5 – AjaxPro example in action&lt;/p&gt;  &lt;h4&gt;Handling conflicting http handlers&lt;/h4&gt;  &lt;p&gt;As I mentioned before sometimes multiple http handlers on server may conflict and your application may not work as desired. Hence proper resolution may be required to enable all the handlers perform in harmony. As an example, if you try to use AjaxPro framework with ASP.NET MVC application your application will not work out of the box since MVC framework has a powerful url routing engine that captures all the incoming requests (note that in MVC framework, views are also non-existing resources) including all the resource requests for the non-existing resources the ajaxpro/ non existing folder (refer to web.config above). Hence we need an exclusion for this rule in the ASP.NET MVC url routing engine. The following code in the Global.asax.cs will achieve this:&lt;/p&gt;  &lt;p&gt;public static void RegisterRoutes(RouteCollection routes)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; routes.IgnoreRoute(&amp;quot;ajaxpro/{resource}.ashx&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; :     &lt;br /&gt;}&lt;/p&gt;  &lt;h4&gt;Debugging support&lt;/h4&gt;  &lt;p&gt;As with any application development, debugging support is a must to trace execution points within the code. I test and debug my web applications both in Internet Explorer as well as in Mozilla Firefox. To enable debugging support in IE, you can follow the instructions in &lt;a href="http://www.jonathanboutelle.com/mt/archives/2006/01/howto_debug_jav.html"&gt;Jonathan Boutelle’s blog&lt;/a&gt;. Good thing about IE debugging (I personally use Firefox for all other purposes) is that one can leverage Visual Studio debugger rather than downloading and learning another debugger to debug JavaScript. For Mozilla Firefox, I use &lt;a href="http://www.mozilla.org/projects/venkman/"&gt;Venkman JavaScript Debugger&lt;/a&gt; and strongly recommend it as well.&lt;/p&gt;  &lt;h4&gt;Conclusion&lt;/h4&gt;  &lt;p&gt;I hope that I was able to provide a good insight into AJAX web development from a beginner’s point of view. There are many tools available which are not covered here but the most important thing is to play around with them and find the best combination that works for your needs. And of course if you learn some, share some ! Happy coding !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-5889116027473767095?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/5889116027473767095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=5889116027473767095' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5889116027473767095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5889116027473767095'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2009/07/simple-practical-introduction-to.html' title='Simple &amp;amp; Practical introduction to Asynchronous JavaScript And XML (AJAX)'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_LOoKjxVTcbc/SmHdoM02RnI/AAAAAAAAGlU/4G0FFrdqj2k/s72-c/ClassicWebApp.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-5265810017734913228</id><published>2009-05-31T20:40:00.000-07:00</published><updated>2009-05-31T21:13:37.446-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='checkbox'/><category scheme='http://www.blogger.com/atom/ns#' term='listview'/><category scheme='http://www.blogger.com/atom/ns#' term='fixed width listview'/><category scheme='http://www.blogger.com/atom/ns#' term='column header'/><title type='text'>WPF Tips And Facts</title><content type='html'>&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;Do you know that there is no way (at least from my research and experiments) to hide the control box of a dialog. I tried several ways including using Native GetWindowLong and SetWindowLong to set the border style as fixed dialog but in vein.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;One of the hardest things in WPF is to prevent re-size of a column in ListView. One way is to completely templatize ColumnHeader and comment out the thumb gripper. This approach is listed here: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/fa97b3a3-c5ca-4643-8e95-c2c23032de2c. I like the other approach listed in the article where one can attach a handler like:&lt;br /&gt;&lt;br /&gt;MyListView.AddHandler(Thumb.DragDeltaEvent,&lt;br /&gt;                           new DragDeltaEventHandler(this.OnHeaderResize),&lt;br /&gt;                           true);&lt;br /&gt;&lt;br /&gt;And handle it:&lt;br /&gt;&lt;br /&gt;private void OnHeaderResize(object sender, DragDeltaEventArgs e)&lt;br /&gt;{&lt;br /&gt;Thumb SenderAsThumb = e.OriginalSource as Thumb;&lt;br /&gt;GridViewColumnHeader header = SenderAsThumb.TemplatedParent as GridViewColumnHeader;&lt;br /&gt;&lt;br /&gt;if (header == null)&lt;br /&gt;{&lt;br /&gt;   return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;GridView view = (MyListView.View as GridView);&lt;br /&gt; &lt;br /&gt;// If user tries to resize checkbox column, reset the width to fixed&lt;br /&gt;if (view.Columns[0] == header.Column)&lt;br /&gt;{&lt;br /&gt;   header.Column.Width = FixedWidth;&lt;br /&gt;   e.Handled = true;          &lt;br /&gt;}      &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;ListView and CheckBox - Following is a method to add a checkbox both to the header and to the column rows in the ListView:&lt;br /&gt;&lt;br /&gt;&amp;lt;ListView Height="200" x:Name="MyListView"&gt;&lt;br /&gt;   &amp;lt;ListView.View&gt;&lt;br /&gt;       &amp;lt;GridView&gt;&lt;br /&gt;           &amp;lt;GridViewColumn&gt;&lt;br /&gt;               &amp;lt;GridViewColumn.HeaderTemplate&gt;&lt;br /&gt;                   &amp;lt;DataTemplate&gt;&lt;br /&gt;                       &amp;lt;CheckBox Checked="AllSelectionChanged" Unchecked="AllSelectionChanged"/&gt;&lt;br /&gt;                   &amp;lt;/DataTemplate&gt;&lt;br /&gt;               &amp;lt;/GridViewColumn.HeaderTemplate&gt;&lt;br /&gt;               &amp;lt;GridViewColumn.CellTemplate&gt;&lt;br /&gt;                   &amp;lt;DataTemplate&gt;&lt;br /&gt;                       &amp;lt;CheckBox IsChecked="{Binding Selected}"/&gt;&lt;br /&gt;                   &amp;lt;/DataTemplate&gt;&lt;br /&gt;               &amp;lt;/GridViewColumn.CellTemplate&gt;&lt;br /&gt;           &amp;lt;/GridViewColumn&gt;&lt;br /&gt;           &amp;lt;GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/&gt;&lt;br /&gt;           &amp;lt;GridViewColumn Header="Version" DisplayMemberBinding="{Binding Version}"/&gt;&lt;br /&gt;           &amp;lt;GridViewColumn Header="Path" DisplayMemberBinding="{Binding Path}"/&gt;&lt;br /&gt;       &amp;lt;/GridView&gt;&lt;br /&gt;   &amp;lt;/ListView.View&gt;&lt;br /&gt;&amp;lt;/ListView&gt;&lt;/span&gt;&lt;/span&gt;&lt;gridview allowscolumnreorder="False"&gt;&lt;gridviewcolumn width="25"&gt;&lt;gridviewcolumn.headertemplate&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;&lt;listview height="200" name="MyListView"&gt;&lt;listview.view&gt;&lt;gridview&gt;&lt;gridviewcolumn&gt;&lt;gridviewcolumn.headertemplate&gt;&lt;br /&gt;&lt;br /&gt;You can then handle global check / uncheck like:&lt;br /&gt;&lt;br /&gt;private void AllSelectionChanged(object sender, RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    CheckBox chkBox = sender as CheckBox;&lt;br /&gt;    if (chkBox != null)&lt;br /&gt;    {&lt;br /&gt;        bool check = chkBox.IsChecked.Value;&lt;br /&gt;&lt;br /&gt;        foreach ([YourBoundType] selection in MyListView.Items)&lt;br /&gt;        {&lt;br /&gt;            selection.Selected = check;&lt;br /&gt;        }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/gridviewcolumn.headertemplate&gt;&lt;/gridviewcolumn&gt;&lt;/gridview&gt;&lt;/listview.view&gt;&lt;/listview&gt;&lt;/span&gt;&lt;/span&gt;&lt;/gridviewcolumn.headertemplate&gt;&lt;/gridviewcolumn&gt;&lt;/gridview&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-5265810017734913228?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/5265810017734913228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=5265810017734913228' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5265810017734913228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/5265810017734913228'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2009/05/wpf-tips-and-facts.html' title='WPF Tips And Facts'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-1513710794538668772</id><published>2009-04-19T20:44:00.000-07:00</published><updated>2009-04-19T21:05:28.014-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='create'/><category scheme='http://www.blogger.com/atom/ns#' term='an'/><category scheme='http://www.blogger.com/atom/ns#' term='user control'/><category scheme='http://www.blogger.com/atom/ns#' term='cannot'/><category scheme='http://www.blogger.com/atom/ns#' term='Expression Blend cannot create an instance of user control'/><category scheme='http://www.blogger.com/atom/ns#' term='of'/><category scheme='http://www.blogger.com/atom/ns#' term='instance'/><title type='text'>Expression Blend cannot open your custom control in designer ?</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;Sometimes especially working with off-designer you may end up in situations where Expression Blend can no longer open your user controls. You may get some error like:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Cannot create an instance of [User Control class]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A lot of times even attaching a debugger to Blend/VS and putting breakpoints in your constructor / breaking on error would not yield any benefits. Why?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The reason is Expression Blend and Visual Studio designer(s) have stringent conditions that a user control has to follow in order for its type to be even declared compatible for loading. So if any of these conditions are violated, type will be declared unfit and designer won't even bother locating / invoking the constructor of your user control. I have identified two such conditions (there may be more):&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1. In no path of your inheritance hiararchy can there be an abstract class - So if you have a control that is derived from an abstract control class you are out of luck. Even though your end control is concrete it won't work !&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. You need a public default constructor at each level of inheritance hierarchy - That means even if you have a default constructor in your most derived user control class, it is not sufficient. All base classes must also have public default constructors (even if none of the base classes call it) ! Good news is you can assert if these constructors are called in designer only mode by the following code:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;   throw new InvalidOperationException("Constructor is only meant to be used by designer");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-1513710794538668772?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/1513710794538668772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=1513710794538668772' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/1513710794538668772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/1513710794538668772'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2009/04/expression-blend-cannot-open-your.html' title='Expression Blend cannot open your custom control in designer ?'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-4070002209032321902</id><published>2008-06-11T20:03:00.001-07:00</published><updated>2008-06-14T09:05:56.545-07:00</updated><title type='text'>Dependency Injection Frameworks</title><content type='html'>&lt;h4&gt;Background &lt;/h4&gt; In recent days the concept of dependency injection or inversion of control is much talked about in object oriented world of programming. I decided to give an introduction of this concept to people who want to understand this concept with little effort and use it effectively.   &lt;h4&gt;Introduction &lt;/h4&gt;  &lt;p&gt;So what is dependency injection anyway? Simply put it is capability of a consumer to consume a component without knowing in advance specifics/origination of the consumed component.&lt;/p&gt;  &lt;p&gt;&lt;img height="52" alt="image_thumb1.png" src="http://www.codeproject.com/KB/architecture/DependencyInjection-1/image_thumb1.png" width="244" /&gt;&lt;/p&gt;  &lt;p&gt;Now you would ask, what’s new about this? Isn’t this why we have interfaces? I will explain this more clearly by taking an example of a design pattern that is much closer to dependency injection design pattern; that is object creation or factory framework. Consider a typical factory pattern as shown in the figure below. &lt;/p&gt;  &lt;p&gt;&lt;img height="153" alt="image_thumb2.png" src="http://www.codeproject.com/KB/architecture/DependencyInjection-1/image_thumb2.png" width="298" /&gt;&lt;/p&gt;  &lt;p&gt;However, there is a subtle difference between the factory pattern shown above and truly desired object oriented abstraction. The fact that the class factory actually knows about the consumed class (which implements the desired interface that was originally requested by the consumer) breaks this abstraction and plug and play feature. This is exactly where dependency injection framework comes in. &lt;/p&gt;  &lt;h4&gt;Motivation&lt;/h4&gt;  &lt;p&gt;The motivation for dependency injection framework comes from the concepts of &amp;quot;Inversion of Control&amp;quot; and extensibility. Applications now a days are providing more and more extension points to enrich functionality of solutions. Extended plugins in such cases really take on the control from the container that hosts them in the first place (hence the term &amp;quot;Inversion of Control&amp;quot;). Hence dependency injection enables abstraction of dependencies at design time from dynamic binding at runtime. This way extension points can be instantiated, injected as properties or in constructor of the dependent object with dynamic configuration. A great example of such an application is Eclipse (&lt;a href="http://www.eclipse.org"&gt;www.eclipse.org&lt;/a&gt;).&lt;/p&gt;  &lt;h4&gt;Dependency Injection Frameworks &lt;/h4&gt;  &lt;p&gt;In the dependency injection framework, the consumer specifies a set of dependencies that it requires to be fulfilled in order to perform an operation. During runtime a configuration / declarative effort is required to specify consumable objects that can fulfill a set of dependencies. An assembler / runtime component can then perform the necessary binding prior to code execution or notify failure via exceptions. Following figure depicts this behavior.&lt;/p&gt;  &lt;p&gt;&lt;img height="227" alt="image_thumb3.png" src="http://www.codeproject.com/KB/architecture/DependencyInjection-1/image_thumb3.png" width="448" /&gt;&lt;/p&gt;  &lt;p&gt;Dependency injection frameworks really was made possible by new generation object oriented languages that supported metadata access capabilities such as reflection and dynamic code generation / loading. The idea however is much older and can be seen in dynamic linked libraries and even COM.&lt;/p&gt;  &lt;p&gt;There are many frameworks that aid in dependency injection. I will discuss one of the major framework known as Spring.NET (&lt;a href="http://www.springframework.net/"&gt;http://www.springframework.net/&lt;/a&gt;). Spring.NET implements many proven design patterns that makes building enterprise applications easier. But I will just focus on dependency injection part of Spring.NET.&lt;/p&gt;  &lt;h4&gt;A simple example of dependency injection using Spring.NET &lt;/h4&gt;  &lt;p&gt;Trust me even sample examples that ship with Spring.NET aren’t simple. So I decided to make a small startup example to demonstrate how we can use Spring.NET to solve factory creation scenario discussed above.&lt;/p&gt;  &lt;p&gt;For building this code I used Visual Studio.NET 2008 along with Spring.NET binaries that I obtained from &lt;a href="http://www.springframework.net/"&gt;http://www.springframework.net&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;I then created a sample console project called SpringDotNETExample and added reference to Spring.Core assembly to the project (this assembly can be found in the bin folder of your Spring.NET installation directory. For me it was c:\Program Files\Spring.NET 1.1.2\bin\net\2.0\debug\Spring.Core.dll). &lt;/p&gt;  &lt;p&gt;The scenario is very simple. We have a generic interface ISayHello that has a string property SayHello as follows: &lt;/p&gt;  &lt;p&gt;namespace SpringDotNETExample    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public interface ISayHello     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; String SayHello { get; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;I then created a class WorldSayHello that implements ISayHello as following:&lt;/p&gt;  &lt;p&gt;namespace SpringDotNETExample&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;{&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public class WorldSayHello : ISayHello&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public string SayHello&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return &amp;quot;Hello Friend!&amp;quot;; }&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;At runtime I want to bind my configuration to create WorldSayHello as concrete implementation for ISayHello. But this mapping will be transparent to my main program which will use Spring.NET assembler to request instance of mapped object. For this example I would assume that main program requests this object via key “ISayHelloInterface” that must correspond to the mapping.&lt;/p&gt;  &lt;p&gt;To create the mapping I created a mapping in my application configuration file app.config. Following are the contents of this file. I have bolded the interesting parts of this file, rest are just Spring.NET essentials that are less interesting.&lt;/p&gt;  &lt;p&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;    &lt;br /&gt;&amp;lt;configuration&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;configSections&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;sectionGroup name=&amp;quot;spring&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;section name=&amp;quot;context&amp;quot; type=&amp;quot;Spring.Context.Support.ContextHandler, Spring.Core&amp;quot; /&amp;gt;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;section name=&amp;quot;objects&amp;quot; type=&amp;quot;Spring.Context.Support.DefaultSectionHandler, Spring.Core&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/sectionGroup&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;/configSections&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;spring&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;context&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;resource uri=&amp;quot;config://spring/objects&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/context&amp;gt;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;objects xmlns=&amp;quot;http://www.springframework.net&amp;quot;&amp;gt;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;description&amp;gt;An example that demonstrates simple IoC features.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/description&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;object name=&amp;quot;ISayHelloInterface&amp;quot; type=&amp;quot;SpringDotNETExample.WorldSayHello, SpringDotNETExample&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;/objects&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;/spring&amp;gt;     &lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;  &lt;p&gt;Now my program simply requests the object mapped to key ISayHelloInterface to obtain an implementation of ISayHello interface. Notice that the mapping can be changed without compiling the code. This can provide immense versioning capabilities. Following is my main program:&lt;/p&gt;  &lt;p&gt;using System;    &lt;br /&gt;using Spring.Context;     &lt;br /&gt;using Spring.Context.Support;     &lt;br /&gt;    &lt;br /&gt;namespace SpringDotNETExample     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; class Program     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; static void Main(string[] args)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IApplicationContext ctx = ContextRegistry.GetContext();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ISayHello hello = (ISayHello)ctx.GetObject(&amp;quot;ISayHelloInterface&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Console.WriteLine(hello.SayHello);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Running the program yields the following output :)&lt;/p&gt;  &lt;p&gt;Hello Friend!    &lt;br /&gt;Press any key to continue . . .&lt;/p&gt;  &lt;p&gt;In my next articles I will discuss some more advance concepts in dependency injection such as constructor injection. So stay tuned !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-4070002209032321902?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/4070002209032321902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=4070002209032321902' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/4070002209032321902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/4070002209032321902'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2008/06/dependency-injection-and-object.html' title='Dependency Injection Frameworks'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-1246114906445265565</id><published>2008-03-30T02:17:00.000-07:00</published><updated>2008-03-31T00:08:29.196-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sync'/><category scheme='http://www.blogger.com/atom/ns#' term='filesystem'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><title type='text'>Microsoft Sync Framework</title><content type='html'>&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;I work for Microsoft in the Windows Live division as a Software Design Engineer. One of the most interesting problems in the distributed world is managing and synchronizing changes in data elements on various endpoints. Microsoft released a CTP of its sync framework that is out for pre RTM preview (&lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/sync/default.aspx"&gt;&lt;span style="font-size:85%;"&gt;http://msdn2.microsoft.com/en-us/sync/default.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;).&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;The API consists of three major components:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Sync runtime - This is the actual sync runtime that performs transfer of knowledge and metadata and performs actual synchronization. This is the actual underlying sync engine.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Metadata store - Keeps track of metadata of elements at a given endpoint. The API includes a SQL CE implementation of metadata store that can be used out of the box. This component can be customized to address a specific solution.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Providers - The actual storage provider for elements. The API includes the filesystem and rss providers out of the box. This again can be customized and custom providers can be plugged into the sync framework.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Customization of metadata store and providers is interesting as it can be utilitzed in providing sync solutions that operate on differential data sync algorithms. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Following is an example of file syncing between two file system providers. The example utilizes CTP2 of Microsoft Sync Framework (&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=C88BA2D1-CEF3-4149-B301-9B056E7FB1E6"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=C88BA2D1-CEF3-4149-B301-9B056E7FB1E6&lt;/a&gt;).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;using System;&lt;br /&gt;using System.IO;&lt;br /&gt;using Microsoft.Synchronization;&lt;br /&gt;using Microsoft.Synchronization.Files;&lt;br /&gt;namespace MySamples.FileSystemSync&lt;br /&gt;{&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;         // Folders to be synced&lt;br /&gt;         static string folderA = Environment.CurrentDirectory + "\\A";&lt;br /&gt;         static string folderB = Environment.CurrentDirectory + "\\B";&lt;br /&gt;        &lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;         static void Main(string[] args)&lt;br /&gt;         {&lt;br /&gt;                  // Prepare directories for syncing&lt;br /&gt;                  PrepareDirectory(folderA);&lt;br /&gt;                  PrepareDirectory(folderB);&lt;br /&gt;                 &lt;br /&gt;                  &lt;/span&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;// Create file system provider&lt;br /&gt;                  FileSyncProvider providerA = new FileSyncProvider(Guid.NewGuid(), folderA);&lt;br /&gt;                  FileSyncProvider providerB = new FileSyncProvider(Guid.NewGuid(), folderB);&lt;br /&gt;&lt;br /&gt;                  // Create a file in folders&lt;br /&gt;                  File.WriteAllText(Path.Combine(folderA, "A.txt"), "This file is created by A");&lt;br /&gt;                  File.WriteAllText(Path.Combine(folderB, "B.txt"), "This file is created by B");&lt;br /&gt;&lt;br /&gt;                  // Ask providers to detect changes&lt;br /&gt;                  providerA.DetectChanges();&lt;br /&gt;                  providerB.DetectChanges();&lt;br /&gt;&lt;br /&gt;                  // Sync changes&lt;br /&gt;                  SyncOrchestrator agent = new SyncOrchestrator();&lt;br /&gt;                  agent.LocalProvider = providerA;&lt;br /&gt;                  agent.RemoteProvider = providerB;&lt;br /&gt;                  agent.Direction = SyncDirectionOrder.UploadAndDownload;&lt;br /&gt;                  agent.Synchronize();&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         static void PrepareDirectory(string directoryName)&lt;br /&gt;         {&lt;br /&gt;                  if (Directory.Exists(directoryName))&lt;br /&gt;                  {&lt;br /&gt;                           Directory.Delete(directoryName, true);&lt;br /&gt;                  }&lt;br /&gt;                  Directory.CreateDirectory(directoryName);&lt;br /&gt;         }&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;At the end of running the sample notice how both folders A and B both have A.txt and B.txt.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-1246114906445265565?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/1246114906445265565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=1246114906445265565' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/1246114906445265565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/1246114906445265565'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2008/03/microsoft-sync-framework.html' title='Microsoft Sync Framework'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7294975990662761436.post-2895137883416232537</id><published>2007-11-07T18:40:00.000-08:00</published><updated>2007-11-07T19:12:42.734-08:00</updated><title type='text'>Embed resources in .NET assemblies</title><content type='html'>&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; To embed binary resources within .NET assembly and avoid file dependencies&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;strong&gt;Problem:&lt;/strong&gt; I was performing unit testing for my project and realized that I needed a file to be present in the same directory as the assembly. Now Visual Studio test project creates an out folder where it copies the binaries for execution. Initially I tried to include my binary file in the project and from the properties window set "Copy to Output Directory" to "Copy Always" hoping that after compilation file will be copied to the output folder and Visual Studio test framework will deploy it to the out folder. While the file was generated in the output folder (\bin\Output) it wasn't copied to the out folder at runtime (surprise surprise). So I thought of a broader solution to this fundamental problem. Answer: embed binaries in the assembly and extract them at runtime :).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Assume that embedded file is called myfile.bin. First step is to create a resource file in the project. This can be done from project properties -&gt; Resources tab.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;From resources window choose to add an existing file to the resources and select myfile.bin&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Use code below to extract the file at runtime at Assembly's execution path.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;strong&gt;Code:&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;private void ExtractFile()&lt;br /&gt;{&lt;br /&gt;Assembly currentAssembly = Assembly.GetExecutingAssembly();&lt;br /&gt;string outputPath = Path.Combine(Path.GetDirectoryName(currentAssembly.Location), "myfile.bin");&lt;br /&gt;using (FileStream fStream = new FileStream(outputPath, FileMode.Create))&lt;br /&gt;{&lt;br /&gt;fStream.Write(Resources.myfile, 0, Resources.myfile.Length);&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7294975990662761436-2895137883416232537?l=ashishkaila.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ashishkaila.blogspot.com/feeds/2895137883416232537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7294975990662761436&amp;postID=2895137883416232537' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2895137883416232537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7294975990662761436/posts/default/2895137883416232537'/><link rel='alternate' type='text/html' href='http://ashishkaila.blogspot.com/2007/11/embed-resources-in-net-assemblies.html' title='Embed resources in .NET assemblies'/><author><name>Ashish Kaila</name><uri>http://www.blogger.com/profile/01788895917076558081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
