<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Guy Burstein : Visual Studio 2010</title><link>http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx</link><description>Tags: Visual Studio 2010</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>WF/WCF using Visual Studio 2010 and .NET Framework 4 Training Kit</title><link>http://blogs.msdn.com/bursteg/archive/2009/05/19/wf-wcf-using-visual-studio-2010-and-net-framework-4-training-kit.aspx</link><pubDate>Tue, 19 May 2009 16:23:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9627879</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9627879.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9627879</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9627879</wfw:comment><description>&lt;h1&gt;WF/WCF using Visual Studio 2010 and .NET Framework 4 Training Kit&lt;/h1&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF/WCF using Visual Studio 2010 and .NET Framework 4 Training Kit" border="0" alt="WF/WCF using Visual Studio 2010 and .NET Framework 4 Training Kit" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WFWCFusingVisua.NETFramework4TrainingKit_E64B/WF_826378c6-a02d-44ec-8662-a875643db14e.png" width="263" height="51" /&gt;&amp;#160;&amp;#160; &lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF/WCF using Visual Studio 2010 and .NET Framework 4 Training Kit" border="0" alt="WF/WCF using Visual Studio 2010 and .NET Framework 4 Training Kit" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WFWCFusingVisua.NETFramework4TrainingKit_E64B/WCF_449d2a51-c2ce-4abe-80d6-0a156237c6b9.png" width="310" height="47" /&gt; &lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;Microsoft WF/WCF using Visual Studio 2010 and .NET Framework 4 Training Kit&lt;/strong&gt; includes presentations, hands-on labs, and demos. This content is designed to help you learn how to utilize the Visual Studio 2010 features and a variety of WF and WCF new features.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Learn &lt;strong&gt;basic workflow creation&lt;/strong&gt;, hosting and running , and test-drive workflow development. &lt;/li&gt;    &lt;li&gt;Get an introduction to workflow services, communication between workflows and content based correlation of workflow instances. &lt;/li&gt;    &lt;li&gt;Use the flexibility of &lt;strong&gt;Flowchart&lt;/strong&gt; workflow activities to implement non-sequential workflows. &lt;/li&gt;    &lt;li&gt;Learn how to &lt;strong&gt;rehost the workflow designer&lt;/strong&gt; in a WPF desktop application and customize it in several ways. &lt;/li&gt;    &lt;li&gt;Learn how you can leverage some of the main &lt;strong&gt;WF and WCF monitoring&lt;/strong&gt; features to track application execution and troubleshoot problems with services when necessary. &lt;/li&gt;    &lt;li&gt;Learn how &lt;strong&gt;Service discovery&lt;/strong&gt; allows you to locate services on the same subnet using ad hoc discovery, or using a proxy to establish connections with servers regardless of where they are. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This version of the training kit is compatible with &lt;a href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/05/18/visual-studio-2010-beta-1-is-available-for-msdn-subscribers.aspx"&gt;Visual Studio 2010 Beta 1&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Download &lt;a href="http://code.msdn.microsoft.com/wcfwf4/Release/ProjectReleases.aspx?ReleaseId=2698"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9627879" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/WF4/default.aspx">WF4</category></item><item><title>WF 4.0: Long Running Custom Activities with Bookmarks and NativeActivity</title><link>http://blogs.msdn.com/bursteg/archive/2009/05/19/wf-4-0-long-running-custom-activities-with-bookmarks-and-nativeactivity.aspx</link><pubDate>Tue, 19 May 2009 15:40:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9627785</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9627785.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9627785</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9627785</wfw:comment><description>&lt;h1&gt;WF 4.0: Long Running Custom Activities with Bookmarks and NativeActivity&lt;/h1&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0: Long Running Custom Activities Bookmarks NativeActivity" border="0" alt="WF 4.0: Long Running Custom Activities Bookmarks NativeActivity" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0LongRunningCustomActivitieswithBook_C900/WF23_27f3f317-ca61-4fb3-a994-5986cb0115c8.png" width="314" height="61" /&gt;&lt;/p&gt;  &lt;p&gt;This is another post in my &lt;a href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/05/19/wf-4-0-custom-activities.aspx"&gt;WF 4.0: Custom Activities series&lt;/a&gt;. In a previous post I have talked about creating a code only custom activity that performs a simple task. In this post I’ll talk about creating a more complex activities that takes inputs from the calling program during their execution.&lt;/p&gt;  &lt;p&gt;In the previous post &lt;a href="http://blogs.msdn.com/bursteg/archive/2009/05/19/wf-4-0-code-only-custom-activities-for-atomic-actions-codeactivity-codeactivity-t.aspx"&gt;WF 4.0: Code Only Custom Activities for Atomic Actions | CodeActivity, CodeActivity&amp;lt;T&amp;gt;&lt;/a&gt; I implemented the following activity for reading a string from the console.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ReadString2&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;CodeActivity&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;CodeActivityContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;string&lt;/span&gt; value = &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; context.SetValue(Result, value);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;While this activity will perform the task it is meant to do, it is bloc&lt;strong&gt;king the calling thread and bad for scalability&lt;/strong&gt;. In addition to that It is bound to getting the value from the console only, and it is &lt;strong&gt;not generic enough&lt;/strong&gt; to support another input methods.&lt;/p&gt;  &lt;p&gt;Enter &lt;strong&gt;Bookmarks&lt;/strong&gt;.&lt;/p&gt;  &lt;h3&gt;Using NativeActivity for Complex Activities&lt;/h3&gt;  &lt;p&gt;To create a long running activity, add a new item of type &lt;strong&gt;Workflow Element&lt;/strong&gt; item to the project. Notice that the default activity inherits from &lt;strong&gt;CodeActivity&lt;/strong&gt;.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ReadString3&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;CodeActivity&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;CodeActivityContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;To create complex activities such as long running activities, me need to change the base class and inherit from &lt;strong&gt;NativeActivity&lt;/strong&gt; or &lt;strong&gt;NativeActivity&amp;lt;T&amp;gt;.&lt;/strong&gt; In addition to that, there is a difference between the type of the parameter that the &lt;strong&gt;CodeActivity&lt;/strong&gt; takes for the Execute method and the type that &lt;strong&gt;NativeActivity&lt;/strong&gt; takes. Change the input parameter type from &lt;strong&gt;CodeActivityContext&lt;/strong&gt; to &lt;strong&gt;ActivityExecutionContext&lt;/strong&gt;.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ReadString3&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;NativeActivity&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;ActivityExecutionContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;throw&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;NotImplementedException&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;h3&gt;Enter Bookmarks&lt;/h3&gt;  &lt;p&gt;In previous versions of &lt;strong&gt;Windows Workflow Foundation&lt;/strong&gt; we had the &lt;strong&gt;ExternalDataExchangeService&lt;/strong&gt; and &lt;strong&gt;WorkflowQueue&lt;/strong&gt; when we wanted to build a simple long running activity. In &lt;strong&gt;WF 4.0&lt;/strong&gt; this is much more simple to do using &lt;strong&gt;Bookmarks&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;To use bookmarks we need to:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create a named bookmark and Implement a callback method &lt;/li&gt;    &lt;li&gt;Signal from the caller program &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Register a Named Bookmak&lt;/h3&gt;  &lt;p&gt;The following activity registers a bookmark called “input” with a callback method called &lt;strong&gt;OnBookmarkCallback&lt;/strong&gt;.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ReadString3&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;NativeActivity&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;OutArgument&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; name;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;OutArgument&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; Name&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.name; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ThrowIfOpen();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;this&lt;/span&gt;.name = &lt;span style="color: blue"&gt;value&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;ActivityExecutionContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;context.CreateNamedBookmark(&lt;span style="color: #a31515"&gt;&amp;quot;input&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;BookmarkCallback&lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.OnBookmarkCallback));&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;strong&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; OnBookmarkCallback(&lt;span style="color: #2b91af"&gt;ActivityExecutionContext&lt;/span&gt; context, &lt;span style="color: #2b91af"&gt;Bookmark&lt;/span&gt; bookmark, &lt;span style="color: blue"&gt;object&lt;/span&gt; obj)&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;this&lt;/span&gt;.Name.Set(context, (&lt;span style="color: blue"&gt;string&lt;/span&gt;)obj);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;h3&gt;Signal the workflow from the caller program&lt;/h3&gt;  &lt;p&gt;In a previous post I have talked about &lt;a href="WF 4.0: How to Execute a Worklflow (WorkflowInvoker vs WorkflowInstance)"&gt;the code that is needed to execute a workflow&lt;/a&gt;. Since we are now talking about long running workflows we will start with the default code that is generated for us when we create a new sequential workflow console application that uses the &lt;strong&gt;WorkflowInstance&lt;/strong&gt; that lets know when the workflow instance is idle, and to resume a bookmark:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;...&lt;/p&gt;    &lt;p style="margin: 0px"&gt;myInstance.Run();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;//Get a string from the console and resume the bookmark called “input”&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; input = &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;myInstance.ResumeBookmark(&lt;span style="color: #a31515"&gt;&amp;quot;input&amp;quot;&lt;/span&gt;, input);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;syncEvent.WaitOne();      &lt;br /&gt;...       &lt;br /&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The main program performs the input and delivers the value to the workflow. Using this approach:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The main program is flexible in how it wants to get values from the user and any other input source &lt;/li&gt;    &lt;li&gt;The workflow becomes idle when it is waiting for the input and during that time not consuming any resources from the machine. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;To query the available bookmarks in a workflow instance, we can use the following code:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;IList&lt;/span&gt; bookmarks = myInstance.GetAllBookmarks();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;BookmarkInfo&lt;/span&gt; info &lt;span style="color: blue"&gt;in&lt;/span&gt; bookmarks)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Write(info.BookmarkName);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9627785" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/WF4/default.aspx">WF4</category></item><item><title>WF 4.0: Code Only Custom Activities for Atomic Actions | CodeActivity, CodeActivity&lt;T&gt;</title><link>http://blogs.msdn.com/bursteg/archive/2009/05/19/wf-4-0-code-only-custom-activities-for-atomic-actions-codeactivity-codeactivity-t.aspx</link><pubDate>Tue, 19 May 2009 14:03:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9627584</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9627584.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9627584</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9627584</wfw:comment><description>&lt;h1&gt;WF 4.0: Code Only Custom Activities for Atomic Actions | CodeActivity, CodeActivity&amp;lt;T&amp;gt;&lt;/h1&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0  Code Custom Activities CodeActivity CodeActivity&amp;lt;T&amp;gt;" border="0" alt="WF 4.0  Code Custom Activities CodeActivity CodeActivity&amp;lt;T&amp;gt;" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0CodeOnlyCustomActivitiesforAtomicAc_B180/WF%5B2%5D_84b491c4-5c90-4ea3-a124-672167c54855.png" width="314" height="61" /&gt;&lt;/p&gt;  &lt;p&gt;This is another post in my &lt;a href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/05/19/wf-4-0-custom-activities.aspx"&gt;WF 4.0: Custom Activities series&lt;/a&gt;. In this post I’ll talk about creating a code only custom activity that performs a simple task. I’ll also use input and output parameters and talk about activities that returns a single value.&lt;/p&gt;  &lt;h3&gt;A Simple Code Activity&lt;/h3&gt;  &lt;p&gt;Lets start by building a simple activity that outputs a certain string to the console. To to that, lets add a new item of type &lt;strong&gt;Workflow Element&lt;/strong&gt; (under the Workflow node in the item templates).&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0  Code Custom Activities CodeActivity CodeActivity&amp;lt;T&amp;gt;" border="0" alt="WF 4.0  Code Custom Activities CodeActivity CodeActivity&amp;lt;T&amp;gt;" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0CodeOnlyCustomActivitiesforAtomicAc_B180/image_6a34e51b-f707-4373-a8ef-bb2bca587fff.png" width="480" height="275" /&gt; &lt;/p&gt;  &lt;p&gt;Visual Studio adds a new code file (remember – this is a code-only activity) with a class that inherits from the abstract class &lt;strong&gt;System.Activities.CodeActivity&lt;/strong&gt;.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;OutputString&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;CodeActivity&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;CodeActivityContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;To implement the logic of the atomic action, we just have to code it here. Notice that we don’t have to tell the runtime that the status of this activity is closed or something like this like we had to in WF 3.5.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;OutputString&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;CodeActivity&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;CodeActivityContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Hello world&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;After building the project, the new custom activity will appear in the Toolbox, and can be used in the workflow.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0  Code Custom Activities CodeActivity CodeActivity&amp;lt;T&amp;gt;" border="0" alt="WF 4.0  Code Custom Activities CodeActivity CodeActivity&amp;lt;T&amp;gt;" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0CodeOnlyCustomActivitiesforAtomicAc_B180/image_abaeffc1-dc75-486f-add1-2cb7fe8311ab.png" width="333" height="153" /&gt;&lt;/p&gt;  &lt;h3&gt;Adding Input Parameters to the Custom Activity&lt;/h3&gt;  &lt;p&gt;To add a new input parameter to the activity, we declare a &lt;strong&gt;InArgument&amp;lt;T&amp;gt;&lt;/strong&gt; field and property where T is the type of the parameter.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;     &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;OutputString&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;CodeActivity&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;{&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160; &lt;strong&gt;&lt;span style="color: #2b91af"&gt;InArgument&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; name;&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;InArgument&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; Name&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;get &lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;{ &lt;/strong&gt;&lt;strong&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt; name; &lt;/strong&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;set &lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ThrowIfOpen();&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; name = &lt;span style="color: blue"&gt;value&lt;/span&gt;;&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;CodeActivityContext&lt;/span&gt; context)&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Hello,&amp;#160; &amp;quot;&lt;/span&gt; + &lt;strong&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.Name.Get(context)&lt;/strong&gt;);&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;      &lt;p style="margin: 0px"&gt;}&lt;/p&gt;   &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Note that in the property setter implementation I am calling the base class’ &lt;strong&gt;ThrowIfOpen()&lt;/strong&gt; method. This method throws an InvalidOperationException if the activity has already been prepared for execution and the value cannot be set.&lt;/p&gt;  &lt;p&gt;Also note that in order to get the property value, we do not store the value in a private member in the class, but instead – we use the &lt;strong&gt;InArgument&lt;/strong&gt; class and using the &lt;strong&gt;Get&lt;/strong&gt; method passing it the activity context.&lt;/p&gt;  &lt;h3&gt;Output Parameters to Custom Activities&lt;/h3&gt;  &lt;p&gt;Lets create a simple activity that reads the name from the console.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ReadString&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;CodeActivity&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;strong&gt;&lt;span style="color: #2b91af"&gt;OutArgument&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; outputString;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;OutArgument&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; Output&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return&lt;/span&gt; outputString; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;set &lt;/span&gt;{&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ThrowIfOpen();&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; outputString = &lt;span style="color: blue"&gt;value&lt;/span&gt;;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;CodeActivityContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;string&lt;/span&gt; value = &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; context.SetValue(Output, value);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Notice how the code required for an output argument is similar to the one required for an input argument. Also notice how we set the value back to the output value using the &lt;strong&gt;ActivityContext&lt;/strong&gt; instance.&lt;/p&gt;  &lt;h3&gt;Activities with a Single Output Parameter - CodeActivity&amp;lt;T&amp;gt;&lt;/h3&gt;  &lt;p&gt;The above sample read a string from the console and placed the value in the output parameter. If this is the case we can also inherit from &lt;strong&gt;CodeActivity&amp;lt;T&amp;gt;&lt;/strong&gt;:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ReadString2&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;CodeActivity&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #2b91af"&gt;CodeActivityContext&lt;/span&gt; context)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;string&lt;/span&gt; value = &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; context.SetValue(&lt;strong&gt;Result&lt;/strong&gt;, value);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Inheriting from &lt;strong&gt;CodeActivity&amp;lt;T&amp;gt;&lt;/strong&gt; makes it more simple to write a custom activity that has a single output parameter. It has additional benefits which I’ll talk about in a subsequent post.&lt;/p&gt;  &lt;h3&gt;Summary&lt;/h3&gt;  &lt;p&gt;In this post I talked about creating a &lt;strong&gt;code only custom activities&lt;/strong&gt; that performs a simple task. I have also talked about input and output parameters.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9627584" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/WF4/default.aspx">WF4</category></item><item><title>WF 4.0: How to Execute a Worklflow (WorkflowInvoker vs WorkflowInstance)</title><link>http://blogs.msdn.com/bursteg/archive/2009/05/19/wf-4-0-how-to-execute-a-worklflow-workflowinvoker-vs-workflowinstance.aspx</link><pubDate>Tue, 19 May 2009 12:14:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9627351</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9627351.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9627351</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9627351</wfw:comment><description>&lt;h1&gt;WF 4.0: How to Execute a Worklflow (WorkflowInvoker vs WorkflowInstance)&lt;/h1&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This post is based on &lt;a href="http://blogs.msdn.com/bursteg/Visual%20Studio%202010%20Beta%201"&gt;Visual Studio 2010 Beta 1&lt;/a&gt; which is the latest version available in the time of writing this post, so by the time this technology ships, there are probably things that will be slight different.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Execute Worklflow (WorkflowInvoker WorkflowInstance" border="0" alt="Execute Worklflow (WorkflowInvoker WorkflowInstance" align="right" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0HowtoExecuteaWorklflow_D783/WF_ad3238a0-eed5-4642-8b0e-bfba44d3eccb.png" width="314" height="61" /&gt;There are two ways to execute a workflow:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Using the &lt;strong&gt;WorkflowInstance&lt;/strong&gt; class &lt;/li&gt;    &lt;li&gt;Using the &lt;strong&gt;WorkflowInvoker&lt;/strong&gt; class &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Execute Workflows using WorkflowInstace&lt;/h3&gt;  &lt;p&gt;When you create a new &lt;strong&gt;Sequential Workflow Console Application&lt;/strong&gt;, Visual Studio creates the basic code needed to execute the workflow inside the &lt;strong&gt;Main&lt;/strong&gt; method:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;AutoResetEvent&lt;/span&gt; syncEvent = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AutoResetEvent&lt;/span&gt;(&lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;WorkflowInstance&lt;/span&gt; myInstance = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;WorkflowInstance&lt;/span&gt;(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Sequence1&lt;/span&gt;());&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; myInstance.OnCompleted = &lt;span style="color: blue"&gt;delegate&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;WorkflowCompletedEventArgs&lt;/span&gt; e)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; syncEvent.Set();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; myInstance.OnUnhandledException = &lt;span style="color: blue"&gt;delegate&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;WorkflowUnhandledExceptionEventArgs&lt;/span&gt; e)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(e.UnhandledException.ToString());&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: #2b91af"&gt;UnhandledExceptionAction&lt;/span&gt;.Terminate;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; myInstance.OnAborted = &lt;span style="color: blue"&gt;delegate&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;WorkflowAbortedEventArgs&lt;/span&gt; e)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(e.Reason);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; syncEvent.Set();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; myInstance.Run();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; syncEvent.WaitOne();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;1. A &lt;strong&gt;workflow instance&lt;/strong&gt; is created and gets a reference to the root activity of the workflow. The &lt;strong&gt;WorkflowInstance&lt;/strong&gt; class lets us control the running instance of the workflow and exposes several methods for this such as Run(), Abort(), Cancel(), Load(), Unload etc.&lt;/p&gt;  &lt;p&gt;2. Since the workflow execution is scheduled to another thread, we need to block the main thread until the workflow is completed or terminated. To do this, we:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create an &lt;strong&gt;AutoResetEvent&lt;/strong&gt; initialized to false, &lt;/li&gt;    &lt;li&gt;Set the event to true when the workflow is completed, and &lt;/li&gt;    &lt;li&gt;In the main thread - wait for the workflow to complete before exiting the method. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;3. In order to handle errors in the workflow such as exceptions or termination, in addition to handling the &lt;strong&gt;OnCompleted&lt;/strong&gt; event, we are also handling the &lt;strong&gt;OnHandledException&lt;/strong&gt; and &lt;strong&gt;OnAborted&lt;/strong&gt; events. Note that when the workflow has an unhandled exception, the program can still decide how it wants to end the workflow execution, whether it is by aborting, cancelling or terminating the workflow. If the workflow is terminated, the OnCompleted event will also be raised.&lt;/p&gt;  &lt;h3&gt;Execute Workflows using WorkflowInvoker&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;WorkflowInvoker&lt;/strong&gt; lets you invoke a workflow much more easily than the previous approach. It takes the instance of the workflow or activity to run and executes it synchronously. &lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;WorkflowInvoker&lt;/span&gt;.Invoke(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Sequence1&lt;/span&gt;());&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;There are additional overloads of this method that takes parameters and a TimeSpan in which the workflow should complete within. I’ll talk in more details about passing parameters to workflow in a subsequent post, but in general this is all we have to know about &lt;strong&gt;WorkflowInvoker&lt;/strong&gt;.&lt;/p&gt;  &lt;h3&gt;Choosing between WorkflowInstance and WorkflowInvoker&lt;/h3&gt;  &lt;p&gt;If you have a simple workflow that should run synchronously – use &lt;strong&gt;WorkflowInvoker&lt;/strong&gt;. This is useful also in when unit testing workflows (more on this in a later post).&lt;/p&gt;  &lt;p&gt;If you have a &lt;strong&gt;long running workflow&lt;/strong&gt; that you want to control – persist, abort, cancel etc – use &lt;strong&gt;WorkflowInstance&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9627351" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/WF4/default.aspx">WF4</category></item><item><title>WF 4.0: Building a Hello World Sequential Workflow</title><link>http://blogs.msdn.com/bursteg/archive/2009/05/19/wf-4-0-building-a-hello-world-sequential-workflow.aspx</link><pubDate>Tue, 19 May 2009 12:10:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9627346</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9627346.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9627346</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9627346</wfw:comment><description>&lt;h1&gt;WF 4.0: Building a Hello World Sequential Workflow&lt;/h1&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/WF_ef7c5682-700d-4d29-8c62-27a8b04ed7d7.png" width="314" height="61" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This post is based on &lt;font color="#ff0000"&gt;&lt;a href="Visual Studio 2010 Beta 1"&gt;Visual Studio 2010 Beta 1&lt;/a&gt;&lt;/font&gt; which is the latest version available in the time of writing this post, so by the time this technology ships, there are probably things that will be slight different.&lt;/p&gt;  &lt;p&gt;Start &lt;font color="#ff0000"&gt;&lt;a href="Visual Studio 2010 Beta 1"&gt;Visual Studio 2010 Beta 1&lt;/a&gt;&lt;/font&gt; and create a new &lt;strong&gt;Sequential Workflow Console Application.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_df297f03-d0a5-483b-9d2d-b194278808e2.png" width="480" height="332" /&gt; &lt;/p&gt;  &lt;p&gt;After you click OK, visual studio creates the new projects and creates a new WF project, in which there are some things you should know about:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;img style="border-right-width: 0px; margin: 0px 0px 45px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" align="right" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_dc978f71-2b47-4720-9c0f-e973e331ddca.png" width="202" height="320" /&gt;References&lt;/strong&gt;:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;System.Xaml&lt;/strong&gt; – Now that there are several technologies based on Xaml, this is a new Assembly in .Net Framework 4.0 that contains Xaml services such as serialization. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;System.Activities&lt;/strong&gt; is the assembly that contains the implementation of WF 4.0, and as you can guess, the corresponding namespace is System.Activities and anything beneath it. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;System.Activities.Design&lt;/strong&gt; contains the designers for the activities and the designer re-hosting implementation. Since the new designer is based on WPF, you can also note references to &lt;strong&gt;WindowsBase&lt;/strong&gt;, &lt;strong&gt;PresentationCode&lt;/strong&gt; and &lt;strong&gt;PresentationFramework&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;System.ServiceModel&lt;/strong&gt; contains WCF implementation (as of .Net Framework 3.0) and now &lt;strong&gt;System.ServiceModel.Activities&lt;/strong&gt; contains the activities used for Workflow Services (the integration between WF and WCF). &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Sequence.xaml&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;By default, workflows are created declaratively in WF 4.0 and represented in &lt;strong&gt;.xaml files with no code behind&lt;/strong&gt;. If you open this file with an Xml editor, you will see it clearly.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; ?&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;p:Activity&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;x:Class&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;HelloWorld.Sequence1&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns:p&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/netfx/2009/xaml/activities&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns:s&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;clr-namespace:System;assembly=mscorlib&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns:sad&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;clr-namespace:System.Activities.Debugger;assembly=System.Activities&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns:sadx&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;clr-namespace:System.Activities.Design.Xaml;assembly=System.Activities.Design&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns:x&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;p:Sequence&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;sad:XamlDebuggerXmlReader.FileName&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;C:\...\HelloWorld\Sequence1.xaml&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;p:Sequence&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;p:Activity&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The new WF Designer shows an empty sequence, representing an empty block of execution. Note the warning sign that says that the sequence has no child activities.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_e5f1f87b-fb12-4ca7-8c57-831e23a64e66.png" width="251" height="231" /&gt; &lt;/p&gt;  &lt;p&gt;From the &lt;strong&gt;Procedural&lt;/strong&gt; section in the &lt;strong&gt;Toolbox&lt;/strong&gt;, drag the &lt;strong&gt;WriteLine&lt;/strong&gt; Activity to the design surface. &lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_b37a9769-f994-489e-92f1-5f197935c050.png" width="259" height="213" /&gt; &lt;/p&gt;  &lt;p&gt;Now, you get a warning that the &lt;strong&gt;Text&lt;/strong&gt; property is not set. To set it, go the properties window, and open the &lt;strong&gt;Expression Editor&lt;/strong&gt;. In WF 4.0 you use the Expression to set values to variables and parameters, and you can use either static values (like in this case) or VB. &lt;strong&gt;Yes! Expression are written in VB&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;Type the text you want to display to the console and click OK.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_a55edc5b-969b-4248-90c7-6ffba4770792.png" width="450" height="273" /&gt; &lt;/p&gt;  &lt;p&gt;Now, that the simple workflow is completed, you can use Ctrl + F5 to run it like you normally do.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_cefd08b7-090b-4f36-92ad-4f63b204792f.png" width="480" height="250" /&gt; &lt;/p&gt;  &lt;h3&gt;Debugging a Workflow&lt;/h3&gt;  &lt;p&gt;The debugging experience when debugging a workflow in WF 4.0 is very similar to the debugging experience when using code. You can right click an activity the in designer and select &lt;strong&gt;Insert Breakpoint&lt;/strong&gt;, or use &lt;strong&gt;F9&lt;/strong&gt; to do this.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_fafdf8e7-f0ae-466f-878e-f952b2397b42.png" width="480" height="392" /&gt; &lt;/p&gt;  &lt;p&gt;Once you do this and run the workflow, the debugger highlights the current activity using a yellow border (similar to the yellow background for the current statement when debugging code).&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WF 4.0 Hello World Sequential Workflow" border="0" alt="WF 4.0 Hello World Sequential Workflow" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/WF4.0BuildingaHelloWorldSequentialWorkfl_CBBD/image_1164933d-d9bf-47e4-95b5-aa30be08d7d6.png" width="243" height="184" /&gt; &lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9627346" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/WF4/default.aspx">WF4</category></item><item><title>XAML in .Net 4.0: Attached Properties, IAttachedPropertyStore and AttachablePropertyServices</title><link>http://blogs.msdn.com/bursteg/archive/2009/05/18/xaml-in-net-4-0-attached-properties-iattachedpropertystore-and-attachablepropertyservices.aspx</link><pubDate>Mon, 18 May 2009 17:37:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9625344</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9625344.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9625344</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9625344</wfw:comment><description>&lt;h1&gt;XAML in .Net 4.0: Attached Properties, IAttachedPropertyStore and AttachablePropertyServices&amp;#160; &lt;/h1&gt;  &lt;p&gt;&lt;strong&gt;&lt;img style="border-right-width: 0px; margin: 0px 20px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="new dot net logo" border="0" alt="new dot net logo" align="left" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/XAM.0AttachedPropertiesandIAttachedPrope_C1B2/new%20dot%20net%20logo_d55c5d43-56a4-410d-b9e9-c0b5df3a8195.jpg" width="175" height="49" /&gt; &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This post is based on &lt;font color="#ff0000"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/05/18/visual-studio-2010-beta-1-is-available-for-msdn-subscribers.aspx"&gt;Visual Studio 2010 Beta 1&lt;/a&gt;&lt;/font&gt; which is the latest version available in the time of writing this post, so by the time this technology ships, there are probably things that will be slight different.&lt;/p&gt;  &lt;p&gt;In a previous post I’ve talked about &lt;font color="#ff0000"&gt;&lt;a href="http://blogs.msdn.com/bursteg/archive/2009/05/18/xaml-in-net-4-0-serialization-and-deserialization-using-xamlservices.aspx"&gt;XAML Serialization and Deserialization using XamlServices in .Net Framework 4.0&lt;/a&gt;&lt;/font&gt;. In this post I’ll add to my data classes support for &lt;strong&gt;Attached Properties&lt;/strong&gt;, so that they will be extensible during serialization.&lt;/p&gt;  &lt;h3&gt;Implement System.Xaml.IAttachedPropertyStore interface&lt;/h3&gt;  &lt;p&gt;This interface should be implemented by classes that can store &lt;strong&gt;attached properties&lt;/strong&gt;.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IAttachedPropertyStore&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;int&lt;/span&gt; PropertyCount { &lt;span style="color: blue"&gt;get&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;void&lt;/span&gt; CopyPropertiesTo(&lt;span style="color: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt;, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;[] array,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&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;span style="color: blue"&gt;int&lt;/span&gt; index);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;bool&lt;/span&gt; RemoveProperty(&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt; mi);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;void&lt;/span&gt; SetProperty(&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt; mi, &lt;span style="color: blue"&gt;object&lt;/span&gt; value);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;bool&lt;/span&gt; TryGetProperty(&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt; mi, &lt;span style="color: blue"&gt;out&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt; value);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The simplest way of implementing it, is using a &lt;strong&gt;Dictionary&amp;lt;AttachableMemberIdentifier, object&amp;gt;&lt;/strong&gt; that holds the attached properties. For example, the Book class from the previous post that now implements &lt;strong&gt;IAttachedPropertyStore:&lt;/strong&gt;&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;[&lt;span style="color: #2b91af"&gt;RuntimeNameProperty&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;[&lt;span style="color: #2b91af"&gt;ContentProperty&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Related&amp;quot;&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;&lt;strong&gt;IAttachedPropertyStore&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; ISBN { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Name { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&amp;gt; related = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&amp;gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&amp;gt; Related { &lt;span style="color: blue"&gt;get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.related; } }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160; &lt;strong&gt;#region&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt; IAttachedPropertyStore Members&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt;, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt; attachedProperties =         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt;, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;();&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; CopyPropertiesTo(&lt;span style="color: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt;, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;[] array,&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&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;span style="color: blue"&gt;int&lt;/span&gt; index)&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; attachedProperties.CopyTo(array, index);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; PropertyCount&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; attachedProperties.Count; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; RemoveProperty(&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt; member)&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; attachedProperties.Remove(member);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SetProperty(&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt; member, &lt;span style="color: blue"&gt;object&lt;/span&gt; value)&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; attachedProperties[member] = value;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; TryGetProperty(&lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt; member, &lt;span style="color: blue"&gt;out&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt; value)&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; attachedProperties.TryGetValue(member, &lt;span style="color: blue"&gt;out&lt;/span&gt; value);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;&amp;#160; #endregion&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;h3&gt;Use AttachablePropertyServices&amp;#160; to Attach Properties to Stores&lt;/h3&gt;  &lt;p&gt;After adding support for &lt;strong&gt;Attached Properties&lt;/strong&gt; to our object we can attach additional properties to it. This can be done directly with &lt;strong&gt;System.Xaml.AttachablePropertyServices&lt;/strong&gt; class, but usually, we would prefer creating a class that provides strongly typed methods for those kinds of operations. For example, if we want to add more metadata to the book, such as an indication whether it is in stock or not we can create a class like this:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; InStock { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; Quantity { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;In order to store and retrieve the data from a class that implements &lt;strong&gt;IAttachedPropertyStore&lt;/strong&gt; we can add the following static methods to the StockInfo class:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; InStock { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; Quantity { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;strong&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt; GetStockInfo(&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book)&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt; stockInfo = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;AttachablePropertyServices&lt;/span&gt;.TryGetProperty&amp;lt;&lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt;&amp;gt;(&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; book,&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt;), &lt;span style="color: #a31515"&gt;&amp;quot;StockInfo&amp;quot;&lt;/span&gt;),&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;out&lt;/span&gt; stockInfo);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; stockInfo;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SetStockInfo(&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book, &lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt; stockInfo)&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; {&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;AttachablePropertyServices&lt;/span&gt;.SetProperty(&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; book,&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AttachableMemberIdentifier&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt;), &lt;span style="color: #a31515"&gt;&amp;quot;StockInfo&amp;quot;&lt;/span&gt;),&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; stockInfo);&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Now, we can attach and retrieve the additional data from the instance:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book1 = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; { Name = &lt;span style="color: #a31515"&gt;&amp;quot;First&amp;quot;&lt;/span&gt;, ISBN = 123 };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt;.SetStockInfo(book1, &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt; { InStock = &lt;span style="color: blue"&gt;true&lt;/span&gt;, Quantity = 27 }); &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt; info = &lt;span style="color: #2b91af"&gt;StockInfo&lt;/span&gt;.GetStockInfo(book1);&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;If we decided to serialize the instance with the attached properties assigned to it, we would get a serialized content like this:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;123&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt; xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:XamlSamples;assembly=XamlSamples&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;StockInfo.StockInfo&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;StockInfo&lt;/span&gt;&lt;span style="color: red"&gt; InStock&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt; Quantity&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;27&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;StockInfo.StockInfo&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h3&gt;Summary&lt;/h3&gt;  &lt;p&gt;In this post I extended my data class (Book) with additional properties using the &lt;strong&gt;Attached Properties&lt;/strong&gt; support in &lt;strong&gt;Xaml&lt;/strong&gt;: Implementing the &lt;strong&gt;IAttachedPropertyStore&lt;/strong&gt; interface by the data class and setting and getting the values using &lt;strong&gt;AttachablePropertyServices&lt;/strong&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9625344" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/Xaml/default.aspx">Xaml</category></item><item><title>XAML in .Net 4.0: Serialization and Deserialization using XamlServices</title><link>http://blogs.msdn.com/bursteg/archive/2009/05/18/xaml-in-net-4-0-serialization-and-deserialization-using-xamlservices.aspx</link><pubDate>Mon, 18 May 2009 17:33:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9625337</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9625337.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9625337</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9625337</wfw:comment><description>&lt;h1&gt;XAML in .Net 4.0: Serialization and Deserialization using XamlServices&lt;/h1&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px 20px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Serialization and Deserialization using XamlServices" border="0" alt="Serialization and Deserialization using XamlServices" align="left" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/Ne.0XamlSerializationandDeserialization_9AD9/new%20dot%20net%20logo_19ce8458-110a-49f8-98db-410de8787265.jpg" width="175" height="49" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This post is based on &lt;font color="#ff0000"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/05/18/visual-studio-2010-beta-1-is-available-for-msdn-subscribers.aspx"&gt;Visual Studio 2010 Beta 1&lt;/a&gt;&lt;/font&gt; which is the latest version available in the time of writing this post, so by the time this technology ships, there are probably things that will be slight different.&lt;/p&gt;  &lt;p&gt;In order to &lt;strong&gt;serialize and deserialize using XAML in .Net Framework 4.0&lt;/strong&gt; we have to reference a new assembly called &lt;strong&gt;System.Xaml.dll&lt;/strong&gt;. Since XAML was originally used only in WPF, some features are dependent on classes that are inside &lt;strong&gt;WindowsBase.dll&lt;/strong&gt;.&lt;/p&gt;  &lt;h3&gt;Serialize to Xaml with XamlServices&lt;/h3&gt;  &lt;p&gt;Assuming we have a class called &lt;strong&gt;Book&lt;/strong&gt;, that is defined like this:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Name { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; ISBN { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;In order to serialize it, we use &lt;strong&gt;System.Xaml.XamlServices&lt;/strong&gt; class:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book1 = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; { Name = &lt;span style="color: #a31515"&gt;&amp;quot;First&amp;quot;&lt;/span&gt;, ISBN = 123 };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; bookFileName = &lt;span style="color: #a31515"&gt;&amp;quot;book.xaml&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;TextWriter&lt;/span&gt; writer = &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.CreateText(bookFileName))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;XamlServices&lt;/span&gt;.Save(writer, book1);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The output file should contain the following content:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;123&amp;quot;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;My first book&amp;quot;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:XamlSamples;assembly=XamlSamples&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;If we have a more complex object graph, for example if each book had a list of related books:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; ...&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;strong&gt;&lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&amp;gt; related = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&amp;gt;();&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&amp;gt; Related { &lt;span style="color: blue"&gt;get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.related; } }&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Then for the following books with relations:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;     &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;       &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book1 = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; { Name = &lt;span style="color: #a31515"&gt;&amp;quot;First&amp;quot;&lt;/span&gt;, ISBN = 123 };&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book2 = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; { Name = &lt;span style="color: #a31515"&gt;&amp;quot;Second&amp;quot;&lt;/span&gt;, ISBN = 456 };&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book3 = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; { Name = &lt;span style="color: #a31515"&gt;&amp;quot;Third&amp;quot;&lt;/span&gt;, ISBN = 789 };&lt;/p&gt;        &lt;p style="margin: 0px"&gt;book1.Related.Add(book2);&lt;/p&gt;        &lt;p style="margin: 0px"&gt;book1.Related.Add(book3);&lt;/p&gt;        &lt;p style="margin: 0px"&gt;book2.Related.Add(book1);&lt;/p&gt;        &lt;p style="margin: 0px"&gt;book3.Related.Add(book1);&lt;/p&gt;     &lt;/div&gt;   &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The result will be:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;     &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;__ReferenceID0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;123&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First&amp;quot;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:XamlSamples;assembly=XamlSamples&amp;quot;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;456&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Second&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&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;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;__ReferenceID0&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;789&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Third&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&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;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;__ReferenceID0&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;   &lt;/div&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Notice that the first book is now being identified using the &lt;strong&gt;x:Name&lt;/strong&gt; property and its unique id is &lt;strong&gt;__ReferenceID0&lt;/strong&gt;. This ID is also used to list the related books of the second book. Also note that there is no need to create a unique id to the second book because it is represented as a child element of the first one.&lt;/p&gt;  &lt;p&gt;If we wanted to use the Name property of the books as the unique identifier, we could use the &lt;strong&gt;System.Windows.Markup.RuntimeNamePropertyAttribute&lt;/strong&gt; in &lt;strong&gt;WindowsBase.dll&lt;/strong&gt;:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;strong&gt;[&lt;span style="color: #2b91af"&gt;RuntimeNameProperty&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;)]&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; ...&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Now, the output will be:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;     &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;       &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;123&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First&amp;quot;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:XamlSamples;assembly=XamlSamples&amp;quot;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;456&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Second&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&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;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;First&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;789&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Third&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&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;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;First&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book.Related&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;     &lt;/div&gt;   &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Note that there is no x:Name attribute.&lt;/p&gt;  &lt;p&gt;If we also want to take out the &amp;lt;Book.Related&amp;gt; nodes, and set its content to be the content node of the Book type, we can use the &lt;strong&gt;System.Windows.Markup.ContentPropertyAttribute&lt;/strong&gt; in &lt;strong&gt;WindowsBase.dll&lt;/strong&gt;.&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;[&lt;span style="color: #2b91af"&gt;RuntimeNameProperty&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;strong&gt;[&lt;span style="color: #2b91af"&gt;ContentProperty&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Related&amp;quot;&lt;/span&gt;)]&lt;/strong&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; ...&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Now, the result is much simpler:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;     &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;123&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First&amp;quot;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:XamlSamples;assembly=XamlSamples&amp;quot;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;456&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Second&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;First&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: red"&gt; ISBN&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;789&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Third&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;First&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Reference&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: #a31515"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Book&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;   &lt;/div&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h3&gt;Deserialize from Xaml with XamlServices&lt;/h3&gt;  &lt;p&gt;In order to deserialize an object graph from .xaml file, we can use &lt;strong&gt;XamlServices.Load&lt;/strong&gt; method:&lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 11pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;TextReader&lt;/span&gt; reader = &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.OpenText(bookFileName))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; book = (&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;XamlServices&lt;/span&gt;.Load(reader);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Book {0} (ISBN:{1})&amp;quot;&lt;/span&gt;, book.Name, book.ISBN);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Related Books:&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Book&lt;/span&gt; relatedBook &lt;span style="color: blue"&gt;in&lt;/span&gt; book.Related)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;\t{0} (ISBN:{1})&amp;quot;&lt;/span&gt;, relatedBook.Name, relatedBook.ISBN);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;After deserialization, the object graph is just as it was before serialization, and the output is:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Serialization and Deserialization using XamlServices" border="0" alt="Serialization and Deserialization using XamlServices" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/Ne.0XamlSerializationandDeserialization_9AD9/image_524841df-beef-4dc2-b099-1e113f139f6d.png" width="480" height="297" /&gt; &lt;/p&gt;  &lt;h3&gt;Summary&lt;/h3&gt;  &lt;p&gt;In this post I showed basic samples of &lt;strong&gt;serialization and deserialization of object graphs uisng XamlServices in System.Xaml as part of the .Net Framework 4.0&lt;/strong&gt;. In later post I'll talk about some more advanced features such as Attached Properties and more.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9625337" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/Xaml/default.aspx">Xaml</category></item><item><title>Visual Studio 2010 and .NET Framework 4.0 Training Kit - November Preview is now Available</title><link>http://blogs.msdn.com/bursteg/archive/2008/11/13/visual-studio-2010-and-net-framework-4-0-training-kit-november-preview-is-now-available.aspx</link><pubDate>Thu, 13 Nov 2008 14:36:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9065953</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9065953.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9065953</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9065953</wfw:comment><description>&lt;h1&gt;Visual Studio 2010 and .NET Framework 4.0 Training Kit - November Preview is now Available&lt;/h1&gt;  &lt;p&gt;&lt;img style="margin: 0px; display: inline" title="Visual Studio 2010 and .NET Framework 4.0 Training Kit " border="0" alt="Visual Studio 2010 and .NET Framework 4.0 Training Kit " align="right" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/Vis.0TrainingKitNovemberPreviewisnowAvai_BEDD/VS2010_96f53465-46f6-4d24-9002-8264539f6ae8.jpg" width="262" height="49" /&gt; The November preview of the &lt;b&gt;Visual Studio 2010 and .NET Framework 4.0 Training Kit&lt;/b&gt; is now available for &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=752CB725-969B-4732-A383-ED5740F02E93&amp;amp;displaylang=en"&gt;download&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;This preview includes the following content:&lt;/p&gt;  &lt;h4&gt;Presentations&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Overview of the .NET Framework 4.0        &lt;br /&gt;&lt;/b&gt;This presentation goes over the new technologies and enhancements being made in the version 4 release of the .NET Framework.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Overview of the Visual Studio 2010        &lt;br /&gt;&lt;/b&gt;This presentation covers is a high-level over of the value propositions for Visual Studio 2010 and a walkthrough some of the great features being added to the IDE. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Hands-on-Labs&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Visual Studio 2010: Office Programmability        &lt;br /&gt;&lt;/b&gt;In this lab you will see how new features in Visual Studio 2010, C# 4.0, and Visual Basic 10 make it easer to develop applications leveraging Microsoft Office. Additionally, you'll see a number of other powerful features which speed other elements of Office development.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Visual Studio 2010: Test Driven Development        &lt;br /&gt;&lt;/b&gt;Visual Studio 2010 brings with it several enhancements to help cut development friction and enable the developer to focus on the task at hand: writing high-quality code. In the following exercises we'll highlight several of the new features that the TDD developer can use to enhance his/her development cadence. Visual Studio helps your cadence by cutting the number of keystrokes to accomplish frequently performed tasks, speeds navigation through your solution, and enables you to use test frameworks other than MSTest.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Parallel Extensions: Building Multicore Applications with .NET        &lt;br /&gt;&lt;/b&gt;Microsoft's Parallel Computing Platform (PCP) is providing tools enabling developers to leverage the power of Multicore processors in an efficient, maintainable, and scalable manner. Parallel Extensions to the .NET Framework brings several important concepts into this toolset. In this Hands-On Lab, you will learn how to parallelize an existing algorithm by using the static Parallel helper class, create and run Tasks, use the Future&amp;lt;T&amp;gt; class to create and run Tasks that return a value and use Parallel LINQ (PLINQ) to optimize LINQ queries to exectue in a parallel environment       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Introduction To Managed Extensibility Framework (MEF)        &lt;br /&gt;&lt;/b&gt;The Managed Extensibility Framework (MEF) allows developers to provide hooks into their .NET applications for extensions by first and third parties. MEF can be thought of as a general application extension facility. In this Hands-On Lab, you will learn how to define extensibility points for components, perform conditional binding and component creation and import extended assemblies while an application is running.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;ASP.NET AJAX        &lt;br /&gt;&lt;/b&gt;In this Hands-On Lab, you will learn how to leverage new client-side templates to easily bind data to your UI, use the DataView control to render data on the client, extend the template engine by creating custom Markup Extensions, and declaratively instantiate behaviors and controls       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;ASP.NET Dynamic Data        &lt;br /&gt;&lt;/b&gt;ASP.NET Dynamic Data MVC allows developers to create web based applications that dynamically create pages based on the application's data model. ASP.NET Dynamic Data MVC provides scaffolding and templates that are easily customizable and extensible to reflect the custom functionality required for a solution. In this Hands-On Lab, you will learn how to use Dynamic Data MVC to easily render data over forms and then to easily create your own views and enforce data validation.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Intro To Project &amp;quot;Velocity&amp;quot;        &lt;br /&gt;&lt;/b&gt;In this Hands-On Lab, you will learn how to install and configure Velocity, program against Velocity's API and use Velocity's SessionState provider with ASP.NET.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Intro To F#        &lt;br /&gt;&lt;/b&gt;This Hands-On Lab is comprised by the following exercises. Examine the basic F# types including tuples and functions. Discover how the &amp;quot;let&amp;quot; keyword allows values to be bound to identifiers. See that in F# funcations are the same as any other value, and are handled the same way. Demonstrate how this allows advanced langage features such as parially-applied or &amp;quot;curried&amp;quot; functions. Discover how F# lists are built and the power that can be achieved by F#'s &amp;quot;Head + Tail&amp;quot; approach. Demonstrate the powerful pattern matching and recusion capabilities of F#. Demonstrate the power and usefulness of discriminated unions in F#. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9065953" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category></item><item><title>Visual Studio 2010 and .NET Framework 4.0 CTP is Available</title><link>http://blogs.msdn.com/bursteg/archive/2008/10/27/visual-studio-2010-and-net-framework-4-0-ctp-is-available.aspx</link><pubDate>Mon, 27 Oct 2008 20:09:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9018556</guid><dc:creator>Guy Burstein</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bursteg/comments/9018556.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bursteg/commentrss.aspx?PostID=9018556</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bursteg/rsscomments.aspx?PostID=9018556</wfw:comment><description>&lt;h1&gt;Visual Studio 2010 and .NET Framework 4.0 CTP is Available&amp;#160; &lt;/h1&gt;  &lt;h1&gt;&amp;#160;&lt;img style="margin: 0px; display: inline" title="Visual Studio 2010 and .NET Framework 4.0 CTP" border="0" alt="Visual Studio 2010 and .NET Framework 4.0 CTP" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/VisualStudio2010and.NETF.0CTPisAvailable_10655/new%20dot%20net%20logo_8a9b4131-8ac2-42fc-9f2b-4aedc553dfcd.jpg" width="175" height="49" /&gt; &lt;img style="margin: 0px; display: inline" title="Visual Studio 2010 and .NET Framework 4.0 CTP" border="0" alt="Visual Studio 2010 and .NET Framework 4.0 CTP" src="http://blogs.msdn.com/blogfiles/bursteg/WindowsLiveWriter/VisualStudio2010and.NETF.0CTPisAvailable_10655/VS2010_8b794d14-f86d-4295-92a1-c91a4ce5cdae.jpg" width="262" height="49" /&gt; &lt;/h1&gt;  &lt;p&gt;&lt;a href="http://www.microsoft.com/info.aspx?na=22&amp;amp;p=2&amp;amp;SrcDisplayLang=en&amp;amp;SrcCategoryId=10&amp;amp;SrcFamilyId=&amp;amp;u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d922b4655-93d0-4476-bda4-94cf5f8d4814%26DisplayLang%3den" mce_href="http://www.microsoft.com/info.aspx?na=22&amp;amp;p=2&amp;amp;SrcDisplayLang=en&amp;amp;SrcCategoryId=10&amp;amp;SrcFamilyId=&amp;amp;u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d922b4655-93d0-4476-bda4-94cf5f8d4814%26DisplayLang%3den"&gt;Visual Studio 2010 and .NET Framework 4.0 CTP&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Download Microsoft Visual Studio 2010 and the .NET Framework 4.0: The next generation development tools and platform for Windows Vista, the 2007 Office System, and the Web.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9018556" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bursteg/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://blogs.msdn.com/bursteg/archive/tags/.Net+Framework+4.0/default.aspx">.Net Framework 4.0</category></item></channel></rss>