<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>&#60;xaml:Blog x:Name=&#34;Brian Lagunas&#34; /&#62;</title>
	<atom:link href="http://brianlagunas.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://brianlagunas.com</link>
	<description>WPF, SIlverlight, WIndows Phone, and WinRT all in one blog</description>
	<lastBuildDate>Mon, 30 Apr 2012 21:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Building IG Outlook Part 1&#8211;Setting up the Prism Application</title>
		<link>http://brianlagunas.com/2012/04/25/building-ig-outlook-part-1setting-up-the-prism-application/</link>
		<comments>http://brianlagunas.com/2012/04/25/building-ig-outlook-part-1setting-up-the-prism-application/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 19:51:46 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Infragistics]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=695</guid>
		<description><![CDATA[This is the first video in a series that will take you step-by-step on building a Prism application that mimics Microsoft Outlook.  This video covers how to setup a multi-platform Prism application that targets WPF and Silverlight.  I show you how to setup your directory structure, as well as the solution/project structure inside Visual Studio.  <a href='http://brianlagunas.com/2012/04/25/building-ig-outlook-part-1setting-up-the-prism-application/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>This is the first video in a series that will take you step-by-step on building a Prism application that mimics Microsoft Outlook.  This video covers how to setup a multi-platform Prism application that targets WPF and Silverlight.  I show you how to setup your directory structure, as well as the solution/project structure inside Visual Studio.  We also create a functional Silverlight and WPF shell application and see our first glimpse of code sharing with the bootstrapper.</p>
<p>Watch the video on <a href="http://xaml.tv/2012/04/25/building-ig-outlook-part-1-setting-up-the-prism-application/" target="_blank">Xaml TV</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/04/25/building-ig-outlook-part-1setting-up-the-prism-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building IG Outlook&#8211; Introduction to a Prism App</title>
		<link>http://brianlagunas.com/2012/04/23/building-ig-outlook-introduction-to-a-prism-app/</link>
		<comments>http://brianlagunas.com/2012/04/23/building-ig-outlook-introduction-to-a-prism-app/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 01:41:13 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Infragistics]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[NetAdvantage]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=692</guid>
		<description><![CDATA[Often when learning a technology you start by searching the web.&#160; You look for videos, blogs, articles, samples, and examples.&#160; What you start to realize is that everything you find is very simple “demo” code.&#160; That’s code that shows how to implement a simple feature in a non-realistic demo.&#160; Then you start looking for “production” <a href='http://brianlagunas.com/2012/04/23/building-ig-outlook-introduction-to-a-prism-app/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Often when learning a technology you start by searching the web.&#160; You look for videos, blogs, articles, samples, and examples.&#160; What you start to realize is that everything you find is very simple “demo” code.&#160; That’s code that shows how to implement a simple feature in a non-realistic demo.&#160; Then you start looking for “production” code examples.&#160; That’s code that represents a more realistic implementation of an application in a production environment.&#160; This type of resource is very difficult to find.&#160; Why?&#160; Mainly, because it is very time consuming to create such examples.</p>
<p>This scenario is no different when trying to learn Prism.&#160; You probably first start by reading though the <a href="http://msdn.microsoft.com/en-us/library/gg406140.aspx" target="_blank">documentation</a>.&#160; Next, you head on over to Pluralsight and watch my <a href="http://www.pluralsight-training.net/microsoft/Courses/TableOfContents?courseName=prism-introduction" target="_blank">Introduction to Prism</a> course.&#160; Now that you know all the basics you start searching the web for examples for specific scenarios.&#160; How do I do “x” and “y”?&#160; How do I apply this sample code to my application?&#160; Hopefully I can help you answer those questions.</p>
<p>I am starting a new video series called Building IG Outlook.&#160; I will take you step-by-step on building a Prism application that mimics Microsoft Outlook.&#160; We will be discussing the following key areas in no specific order:</p>
<ol>
<li>Application architecture/structure</li>
<li>Multi-platform support (WPF and Silverlight)</li>
<li>Commanding</li>
<li>Event aggregation</li>
<li>Custom RegionAdapters</li>
<li>Custom RegionBehaviors</li>
<li>Navigation (OutlookBar, Ribbon, and View interaction)</li>
<li>MVVM (no frameworks needed)</li>
</ol>
<p>Like most production applications we will have a dependency on a 3rd party toolset.&#160; I will be using Infragistics NetAdvantage for WPF and Silverlight.&#160; If you don’t own Infragistics you can download the trial or purchase the suite so you can compile and run all the sample code.&#160; Otherwise, you will have to modify the code to work with your vendor of choice.</p>
<p>I hope this series will help you gain a better understanding of how you can use the various aspects of Prism to build your applications.&#160; This will be a long series and I plan to record at least one a week depending on my traveling schedule.&#160; If you have any questions or would like to see something specific be sure to let me know, and I will see if I can squeeze an example in the application.</p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/04/23/building-ig-outlook-introduction-to-a-prism-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create a Custom Prism RegionAdapter</title>
		<link>http://brianlagunas.com/2012/04/18/create-a-custom-prism-regionadapter/</link>
		<comments>http://brianlagunas.com/2012/04/18/create-a-custom-prism-regionadapter/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 18:53:54 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=689</guid>
		<description><![CDATA[Don’t want to read the article?&#160; Watch the video tutorial on Xaml TV. Prism provides 4 region adapters out of the box for you: ContentControlRegionAdapter SelectorRegionAdaptor ItemsControlRegionAdapter TabControlRegionAdapter (Silverlight only) Well, what happens when you want to use a different control as a region host?&#160; Simple.&#160; You need to write a custom region adapter for <a href='http://brianlagunas.com/2012/04/18/create-a-custom-prism-regionadapter/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Don’t want to read the article?&#160; Watch the video tutorial on <a href="http://xaml.tv/2012/04/18/create-a-custom-prism-regionadapter/" target="_blank">Xaml TV</a>.</p>
<p>Prism provides 4 region adapters out of the box for you:</p>
<ul>
<li>ContentControlRegionAdapter </li>
<li>SelectorRegionAdaptor </li>
<li>ItemsControlRegionAdapter </li>
<li>TabControlRegionAdapter (Silverlight only) </li>
</ul>
<p>Well, what happens when you want to use a different control as a region host?&#160; Simple.&#160; You need to write a custom region adapter for it.&#160; Is it hard you ask?&#160; No it is quite easy.&#160; Let’s write one for the StackPanel.</p>
<p>Start by creating a class the derive from and implements the base abstract class RegionAdapterBase&lt;T&gt;.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:42841886-07a5-4824-b616-f916daec35cc" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">StackPanelRegionAdapter</span> : <span style="color:#2b91af">RegionAdapterBase</span>&lt;<span style="color:#2b91af">StackPanel</span>&gt;<br /> {<br />     <span style="color:#0000ff">public</span> StackPanelRegionAdapter(<span style="color:#2b91af">IRegionBehaviorFactory</span> factory)<br />         : <span style="color:#0000ff">base</span>(factory)<br />     {</p>
<p>     }</p>
<p>     <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> Adapt(<span style="color:#2b91af">IRegion</span> region, <span style="color:#2b91af">StackPanel</span> regionTarget)<br />     {<br />         region.Views.CollectionChanged += (s, e) =&gt;<br />             {<br />                 <span style="color:#0000ff">if</span> (e.Action == <span style="color:#2b91af">NotifyCollectionChangedAction</span>.Add)<br />                 {<br />                     <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">FrameworkElement</span> element <span style="color:#0000ff">in</span> e.NewItems)<br />                     {<br />                         regionTarget.Children.Add(element);<br />                     }<br />                 }</p>
<p>                 <span style="color:#008000">//implement remove</span><br />             };<br />     }</p>
<p>     <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#2b91af">IRegion</span> CreateRegion()<br />     {<br />         <span style="color:#0000ff">return</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">AllActiveRegion</span>();<br />     }<br /> }</div>
</p></div>
</p></div>
<p>Notice that there are two methods we need to implement. Adapt and CreateRegion.&#160; CreateRegion return the type of region we will need.&#160; In our case we want to support multiple views so we need to return an instance of an AllActiveRegion.&#160; If we only needed support for one view at a time we would return a SingleActiveRegion.&#160; The Adapt method is responsible for adapting the region to our control.&#160; This is where we will add and remove the views to or host control.</p>
<p>Now we simply have to tell Prism about our new RegionAdapter.&#160; We do this in the bootstrapper.&#160; Simply override the ConfigureRegionAdapterMappings method as follows:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a055d5d5-0c63-4fe5-a67e-cd8a5b2b7ee3" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> Microsoft.Practices.Prism.Regions.<span style="color:#2b91af">RegionAdapterMappings</span> ConfigureRegionAdapterMappings()<br /> {<br />     <span style="color:#2b91af">RegionAdapterMappings</span> mappings = <span style="color:#0000ff">base</span>.ConfigureRegionAdapterMappings();<br />     mappings.RegisterMapping(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">StackPanel</span>), Container.Resolve&lt;<span style="color:#2b91af">StackPanelRegionAdapter</span>&gt;());<br />     <span style="color:#0000ff">return</span> mappings;<br /> }</div>
</p></div>
</p></div>
<p>That’s it.&#160; Now you can use a StackPanel as a region host:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:acfd8aa2-6c0e-40af-8018-6d9021cfd008" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">StackPanel</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">=&quot;Horizontal&quot;</span><br />            <span style="color:#ff0000"> prism</span><span style="color:#0000ff">:</span><span style="color:#ff0000">RegionManager.RegionName</span><span style="color:#0000ff">=&quot;MyRegion&quot; /&gt;</span></div>
</p></div>
</p></div>
<p>&#160;</p>
<p><a href="http://brianlagunas.com/downloads/source/prism-custom-region-adapter.zip">Download the sample application.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/04/18/create-a-custom-prism-regionadapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate a Property Against a Parent Collection</title>
		<link>http://brianlagunas.com/2012/04/11/validate-a-property-against-a-parent-collection/</link>
		<comments>http://brianlagunas.com/2012/04/11/validate-a-property-against-a-parent-collection/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 00:18:25 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Infragistics]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[XamDataGrid]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=668</guid>
		<description><![CDATA[I was monitoring my Twitter feed, like I always do, and saw a tweet come through asking about how to validate an object’s property against it’s parent ObservableCollection in the Infragistics XamDataGrid.&#160; What this person was trying to accomplish was to validate a duplicate item in his data source.&#160; They have a POCO object the <a href='http://brianlagunas.com/2012/04/11/validate-a-property-against-a-parent-collection/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I was monitoring my Twitter feed, like I always do, and saw a tweet come through asking about how to validate an object’s property against it’s parent ObservableCollection in the <a href="http://www.infragistics.com/" target="_blank">Infragistics</a> XamDataGrid.&#160; What this person was trying to accomplish was to validate a duplicate item in his data source.&#160; They have a POCO object the implements the IDataErrorInfo interface, and an ObservableColletion&lt;POCO&gt; as the data source.&#160; They want to check the ObservableCollection&lt;POCO&gt; for a pre-existing item whenever a property value in a POCO changes.&#160; Obviously this is not a XamDataGrid issue, but rather an object design issue.&#160; So I decided to whip up a quick and dirty solution to solve this particular issue.</p>
<p>The approach I am going to take is to simply keep track of the parent collection from within the POCO object itself.&#160; I really like interfaces, so I started out by defining a simple interface my POCOs will implement.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:529a9bc1-603c-4055-8ca9-4d919906a746" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">interface</span> <span style="color:#2b91af">IHasParent</span><br /> {<br />     <span style="color:#0000ff">object</span> Parent { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</div>
</p></div>
</p></div>
<p>Now let’s take a look at the simple POCO I will be using in this example.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:65d4cc86-7400-4989-b8ee-b7a14c796860" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 400px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Person</span> : <span style="color:#2b91af">INotifyPropertyChanged</span>, <span style="color:#2b91af">IDataErrorInfo</span><br /> {<br />     <span style="color:#0000ff">private</span> <span style="color:#0000ff">string</span> _firstName;<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> FirstName<br />     {<br />         <span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> _firstName; }<br />         <span style="color:#0000ff">set</span><br />         {<br />             _firstName = <span style="color:#0000ff">value</span>;<br />             OnPropertyChanged(<span style="color:#a31515">&quot;FirstName&quot;</span>);<br />         }<br />     }</p>
<p>     <span style="color:#0000ff">private</span> <span style="color:#0000ff">string</span> _lastName;<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> LastName<br />     {<br />         <span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> _lastName; }<br />         <span style="color:#0000ff">set</span><br />         {<br />             _lastName = <span style="color:#0000ff">value</span>;<br />             OnPropertyChanged(<span style="color:#a31515">&quot;LastName&quot;</span>);<br />         }<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">event</span> <span style="color:#2b91af">PropertyChangedEventHandler</span> PropertyChanged;<br />     <span style="color:#0000ff">protected</span> <span style="color:#0000ff">void</span> OnPropertyChanged(<span style="color:#0000ff">string</span> propertyName)<br />     {<br />         <span style="color:#0000ff">var</span> handler = PropertyChanged;<br />         <span style="color:#0000ff">if</span> (handler != <span style="color:#0000ff">null</span>)<br />             handler(<span style="color:#0000ff">this</span>, <span style="color:#0000ff">new</span> <span style="color:#2b91af">PropertyChangedEventArgs</span>(propertyName));<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> <span style="color:#0000ff">this</span>[<span style="color:#0000ff">string</span> columnName]<br />     {<br />         <span style="color:#0000ff">get</span><br />         {<br />             <span style="color:#0000ff">if</span> (columnName == <span style="color:#a31515">&quot;FirstName&quot;</span>)<br />             {<br />                 <span style="color:#0000ff">if</span> (<span style="color:#2b91af">String</span>.IsNullOrWhiteSpace(FirstName))<br />                     <span style="color:#0000ff">return</span> <span style="color:#a31515">&quot;First name cannot be empty&quot;</span>;<br />             }</p>
<p>             <span style="color:#0000ff">if</span> (columnName == <span style="color:#a31515">&quot;LastName&quot;</span>)<br />             {<br />                 <span style="color:#0000ff">if</span> (<span style="color:#2b91af">String</span>.IsNullOrWhiteSpace(LastName))<br />                     <span style="color:#0000ff">return</span> <span style="color:#a31515">&quot;Last name cannot be empty&quot;</span>;<br />             }</p>
<p>             <span style="color:#0000ff">return</span> <span style="color:#2b91af">String</span>.Empty;<br />         }<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Error<br />     {<br />         <span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> <span style="color:#2b91af">String</span>.Empty; }<br />     }<br /> }</div>
</p></div>
</p></div>
<p>Notice that we implement both the INotifyPropertyChanged interfaces as well as the IDataErrorInfo interface.&#160; The Next thing we need is a custom ObservableCollection to use as our data source.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ff50d463-15c6-485f-985c-156a77efe0ab" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">HasParentObservableCollection</span>&lt;T&gt; : <span style="color:#2b91af">ObservableCollection</span>&lt;T&gt;<br /> {<br />     <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> InsertItem(<span style="color:#0000ff">int</span> index, T item)<br />     {<br />         <span style="color:#008000">//set the parent object when a new item is added to our collection</span><br />         <span style="color:#0000ff">if</span> (item != <span style="color:#0000ff">null</span> &amp;&amp; item <span style="color:#0000ff">is</span> <span style="color:#2b91af">IHasParent</span>)<br />             (item <span style="color:#0000ff">as</span> <span style="color:#2b91af">IHasParent</span>).Parent = <span style="color:#0000ff">this</span>;</p>
<p>         <span style="color:#0000ff">base</span>.InsertItem(index, item);<br />     }<br /> }</div>
</p></div>
</p></div>
<p>Notice that we are casting our item as the IHasParent interface and setting the Parent property accordingly.&#160; The next thing we need to do is have our POCO class implement the IHasPerson interface.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:86290b0b-8cad-4705-9067-dff871c468c6" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Person</span> : <span style="color:#2b91af">INotifyPropertyChanged</span>, <span style="color:#2b91af">IDataErrorInfo</span>, <span style="color:#2b91af">IHasParent</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">object</span> Parent { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }</p>
<p>     <span style="color:#0000ff">private</span> <span style="color:#0000ff">string</span> _firstName;<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> FirstName<br />     {<br />         <span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> _firstName; }<br />         <span style="color:#0000ff">set</span><br />         {<br />             _firstName = <span style="color:#0000ff">value</span>;<br />             OnPropertyChanged(<span style="color:#a31515">&quot;FirstName&quot;</span>);<br />         }<br />     }</p>
<p>     <span style="color:#0000ff">private</span> <span style="color:#0000ff">string</span> _lastName;<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> LastName<br />     {<br />         <span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> _lastName; }<br />         <span style="color:#0000ff">set</span><br />         {<br />             _lastName = <span style="color:#0000ff">value</span>;<br />             OnPropertyChanged(<span style="color:#a31515">&quot;LastName&quot;</span>);<br />         }<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">event</span> <span style="color:#2b91af">PropertyChangedEventHandler</span> PropertyChanged;<br />     <span style="color:#0000ff">protected</span> <span style="color:#0000ff">void</span> OnPropertyChanged(<span style="color:#0000ff">string</span> propertyName)<br />     {<br />         <span style="color:#0000ff">var</span> handler = PropertyChanged;<br />         <span style="color:#0000ff">if</span> (handler != <span style="color:#0000ff">null</span>)<br />             handler(<span style="color:#0000ff">this</span>, <span style="color:#0000ff">new</span> <span style="color:#2b91af">PropertyChangedEventArgs</span>(propertyName));<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> <span style="color:#0000ff">this</span>[<span style="color:#0000ff">string</span> columnName]<br />     {<br />         <span style="color:#0000ff">get</span><br />         {<br />             <span style="color:#0000ff">if</span> (columnName == <span style="color:#a31515">&quot;FirstName&quot;</span>)<br />             {<br />                 <span style="color:#0000ff">if</span> (<span style="color:#2b91af">String</span>.IsNullOrWhiteSpace(FirstName))<br />                     <span style="color:#0000ff">return</span> <span style="color:#a31515">&quot;First name cannot be empty&quot;</span>;<br />             }</p>
<p>             <span style="color:#0000ff">if</span> (columnName == <span style="color:#a31515">&quot;LastName&quot;</span>)<br />             {<br />                 <span style="color:#0000ff">if</span> (<span style="color:#2b91af">String</span>.IsNullOrWhiteSpace(LastName))<br />                     <span style="color:#0000ff">return</span> <span style="color:#a31515">&quot;Last name cannot be empty&quot;</span>;</p>
<p>                 <span style="color:#0000ff">if</span> (Parent != <span style="color:#0000ff">null</span> &amp;&amp; Parent <span style="color:#0000ff">is</span> <span style="color:#2b91af">IList</span>&lt;<span style="color:#2b91af">Person</span>&gt;)<br />                 {<br />                     <span style="color:#0000ff">var</span> list = (<span style="color:#2b91af">IList</span>&lt;<span style="color:#2b91af">Person</span>&gt;) Parent;<br />                     <span style="color:#0000ff">if</span> (list.Count(x =&gt; x.LastName == LastName) &gt; 1)<br />                         <span style="color:#0000ff">return</span> <span style="color:#a31515">&quot;This last name already exists.  Please use a different last name.&quot;</span>;<br />                 }<br />             }</p>
<p>             <span style="color:#0000ff">return</span> <span style="color:#2b91af">String</span>.Empty;<br />         }<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Error<br />     {<br />         <span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> <span style="color:#2b91af">String</span>.Empty; }<br />     }<br /> }</div>
</p></div>
</p></div>
<p>Notice how we implemented the check for a duplicate last name.&#160; We simply checked to make sure we are dealing with the LastName property.&#160; Then we cast the Parent as an IList&lt;Person&gt; so that we can perform a simply LINQ query against it.&#160; We check the parent collection for any results that match the LastName property.&#160; If more than one is returned we have a duplicate.</p>
<p>So let’s test this baby using the XamDataGrid as the original poster was attempting to do.&#160; First create our UI.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5111c8ca-8ea5-4792-a525-912591885c8c" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">XamDataGrid</span><span style="color:#ff0000"> Name</span><span style="color:#0000ff">=&quot;xamDataGrid1&quot;&gt;</span><br />     <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">XamDataGrid.FieldLayouts</span><span style="color:#0000ff">&gt;</span><br />         <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">FieldLayout</span><span style="color:#0000ff">&gt;</span><br />             <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">Field</span><span style="color:#ff0000"> Name</span><span style="color:#0000ff">=&quot;FirstName&quot;</span><span style="color:#ff0000"> Label</span><span style="color:#0000ff">=&quot;First Name&quot; /&gt;</span><br />             <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">Field</span><span style="color:#ff0000"> Name</span><span style="color:#0000ff">=&quot;LastName&quot;</span><span style="color:#ff0000"> Label</span><span style="color:#0000ff">=&quot;Last Name&quot; /&gt;</span><br />         <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">FieldLayout</span><span style="color:#0000ff">&gt;</span><br />     <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">XamDataGrid.FieldLayouts</span><span style="color:#0000ff">&gt;</span><br />     <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">XamDataGrid.FieldLayoutSettings</span><span style="color:#0000ff">&gt;</span><br />         <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">FieldLayoutSettings</span><span style="color:#ff0000"> AddNewRecordLocation</span><span style="color:#0000ff">=&quot;OnTop&quot;</span><br />                                  <span style="color:#ff0000"> AllowAddNew</span><span style="color:#0000ff">=&quot;True&quot;</span> <br />                                  <span style="color:#ff0000"> AutoGenerateFields</span><span style="color:#0000ff">=&quot;False&quot;</span> <br />                                  <span style="color:#ff0000"> SupportDataErrorInfo</span><span style="color:#0000ff">=&quot;RecordsAndCells&quot;</span> <br />                                  <span style="color:#ff0000"> DataErrorDisplayMode</span><span style="color:#0000ff">=&quot;Highlight&quot; /&gt;</span><br />     <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">XamDataGrid.FieldLayoutSettings</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">igDP</span><span style="color:#0000ff">:</span><span style="color:#a31515">XamDataGrid</span><span style="color:#0000ff">&gt;</span></div>
</p></div>
</p></div>
<p>Next let’s hook up some data to this bad boy:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7d3714c7-ca40-46b3-a0a9-35ac8e656685" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> MainWindow()<br /> {<br />     InitializeComponent();</p>
<p>     <span style="color:#0000ff">var</span> people = <span style="color:#0000ff">new</span> <span style="color:#2b91af">HasParentObservableCollection</span>&lt;<span style="color:#2b91af">Person</span>&gt;();<br />     people.Add(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Person</span>(){ FirstName = <span style="color:#a31515">&quot;Brian&quot;</span>, LastName = <span style="color:#a31515">&quot;Lagunas&quot;}</span>);<br />     xamDataGrid1.DataSource = people;<br /> }</div>
</p></div>
</p></div>
<p>Now let’s run the app, type a duplicate last name, and see what we get.</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2012/04/collection_validated.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="collection_validated" border="0" alt="collection_validated" src="http://brianlagunas.com/wp-content/uploads/2012/04/collection_validated_thumb.jpg" width="644" height="315" /></a></p>
<p>Cool. Works as expected.&#160; Now there are a number of ways to accomplish this task.&#160; There are even frameworks out there that have already solved this problem for you such as <a href="http://www.lhotka.net/cslanet/" target="_blank">CSLA</a>.&#160; I hope this simple approach helps you find a solution that works for you.</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2012/04/validatepropertyagainstparentcollection.zip">Download the Source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/04/11/validate-a-property-against-a-parent-collection/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Victor Gaudioso&#8211;Preserving his Contributions</title>
		<link>http://brianlagunas.com/2012/04/06/victor-gaudiosopreserving-his-contributions/</link>
		<comments>http://brianlagunas.com/2012/04/06/victor-gaudiosopreserving-his-contributions/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 19:47:14 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[Victor Gaudioso]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=664</guid>
		<description><![CDATA[It was Sunday night.&#160; Victor and I were having a video call on Skype finalizing our plans to host his 70+ Silverlight video tutorials on Xaml TV.&#160; He was late to our meeting because he said he didn’t feel well.&#160; He said that he was recovering from a week long illness, but he quickly assured <a href='http://brianlagunas.com/2012/04/06/victor-gaudiosopreserving-his-contributions/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>It was Sunday night.&#160; Victor and I were having a video call on Skype finalizing our plans to host his 70+ Silverlight video tutorials on <a href="http://xaml.tv/" target="_blank">Xaml TV</a>.&#160; He was late to our meeting because he said he didn’t feel well.&#160; He said that he was recovering from a week long illness, but he quickly assured me he was feeling better.&#160; We chatted for awhile and then ended the meeting with some friendly banter like we always have in the past.</p>
<p>Sadly the next day, on the morning of Monday April 2, 2012, <a href="http://windowspresentationfoundation.com/" target="_blank">Victor Gaudioso</a> passed away.&#160; You didn’t have to know Victor long to know that he was passionate about his work and about his community.&#160; He always went the extra mile to help his fellow developer.&#160; I can write pages about all the good things he has done for his family, friends, and community, but instead I would like encourage you to share your memories of Victor.&#160; Think of how he has influenced you in your life.</p>
<p>The Sunday before he passed, Victor gave me 73 of his videos that we would be posting on Xaml TV.&#160; That night he posted 10 of his Microsoft Starter Kit videos.&#160; Unfortunately he passed before he could finish his effort.&#160; With the blessing of his family and the help of his community, we will be posting all 73 of Victor Gaudioso’s Silverlight video tutorials on Xaml TV.&#160; We will preserve his work and contributions that he made to the community.&#160; They will live on and not disappear with an expiring domain or hosting plan.&#160; His legacy will continue to grow as you remember the fond memories you have of him.</p>
<p>If you would like to help by donating to Victor’s memorial fund or to volunteer, please visit the <a href="http://www.meetup.com/LA-SLUG/pages/WE_LOVE_YOU_VICTOR/" target="_blank">Los Angeles Silverlight User Group</a> site.</p>
<p>Rest in peace my friend.</p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/04/06/victor-gaudiosopreserving-his-contributions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Awarded &#8211; Microsoft Community Contributor Award 2012</title>
		<link>http://brianlagunas.com/2012/03/30/awarded-microsoft-community-contributor-award-2012/</link>
		<comments>http://brianlagunas.com/2012/03/30/awarded-microsoft-community-contributor-award-2012/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 22:56:59 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[awards]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=658</guid>
		<description><![CDATA[Today I received an email informing me that I have been awarded the Microsoft Community Contributor Award.  This is the second time I have been awarded this particular award and it feels just as good this time as it did last time.  I’m not sure how you go about getting nominated for this award, but <a href='http://brianlagunas.com/2012/03/30/awarded-microsoft-community-contributor-award-2012/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Today I received an email informing me that I have been awarded the Microsoft Community Contributor Award.  This is the second time I have been awarded this particular award and it feels just as good this time as it did last time.  I’m not sure how you go about getting nominated for this award, but apparently I am doing something right.</p>
<p>I would like to thank whoever nominated me for this award and Microsoft for listening to that person.  I would most of all like to thank the community.  Without the support of the community I would probably still be a cop. Oh, you probably didn’t know that about me.</p>
<p><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="Brian Lagunas awarded Microsoft Community Contributor Award" src="http://brianlagunas.com/wp-content/uploads/2012/03/MCC12_Logo_Horizontal_Full-color.jpg" alt="Brian Lagunas awarded Microsoft Community Contributor Award" width="500" height="202" border="0" /></p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/03/30/awarded-microsoft-community-contributor-award-2012/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing Xaml TV</title>
		<link>http://brianlagunas.com/2012/03/27/introducing-xaml-tv/</link>
		<comments>http://brianlagunas.com/2012/03/27/introducing-xaml-tv/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 21:44:45 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[xaml tv]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=648</guid>
		<description><![CDATA[I would like announce the creation of a new developer webcast that focuses on Xaml application development called Xaml TV.  The purpose of Xaml TV is to provide quality Xaml content through interviews with individuals, community leaders, and technology experts in the fields of WPF, Silverlight, Windows Phone, and WinRT/Metro.  If it is Xaml we <a href='http://brianlagunas.com/2012/03/27/introducing-xaml-tv/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I would like announce the creation of a new developer webcast that focuses on Xaml application development called <a href="http://xaml.tv/" target="_blank">Xaml TV</a>.  The purpose of Xaml TV is to provide quality Xaml content through interviews with individuals, community leaders, and technology experts in the fields of WPF, Silverlight, Windows Phone, and WinRT/Metro.  If it is Xaml we will cover it.</p>
<p>Currently, Xaml TV is still in the planning phase, heck we don’t even have a logo, and is targeting mid April 2012 to start recording content.  If you would like to submit a talk please feel free to <a href="http://xaml.tv/submit/" target="_blank">submit your topic</a>.  This content is for the community by the community.  Anyone is welcome to participate.  If you have a topic you want to discuss, just submit your session and we will get you scheduled.</p>
<p>Please help spread the word and make this a valuable resource for our Xaml community.</p>
<p>Follow us on Twitter: <a href="https://twitter.com/xamltv" target="_blank">@XamlTV</a> and/or <a href="http://twitter.com/brianlagunas" target="_blank">@BrianLagunas</a></p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/03/27/introducing-xaml-tv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boise Code Camp 2012 Sample Code</title>
		<link>http://brianlagunas.com/2012/03/24/boise-code-camp-2012-sample-code/</link>
		<comments>http://brianlagunas.com/2012/03/24/boise-code-camp-2012-sample-code/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 02:20:10 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Code Camps]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Boise Code Camp]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=627</guid>
		<description><![CDATA[What an awesome day at Boise Code Camp.  We had 400 attendees, 60 sessions, and tons of giveaways.  The top prizes were an Xbox 360 with a game, an iPad2 with accessories, and a Lenovo K1 Tablet with accessories.  Infragistics gave every attendee a license for our NetAdvantage for Windows Phone product, and I gave <a href='http://brianlagunas.com/2012/03/24/boise-code-camp-2012-sample-code/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>What an awesome day at <a href="http://boisecodecamp.com/" target="_blank">Boise Code Camp</a>.  We had 400 attendees, 60 sessions, and tons of giveaways.  The top prizes were an Xbox 360 with a game, an iPad2 with accessories, and a Lenovo K1 Tablet with accessories.  <a href="http://www.infragistics.com/" target="_blank">Infragistics</a> gave every attendee a license for our NetAdvantage for Windows Phone product, and I gave away three NetAdvantage Ultimate products.   Did I mention we had a free breakfast and lunch. NICE!  Congrats to all the winners.</p>
<p>I wore three hats at Boise Code Camp today.  I was a coordinator, sponsor, and speaker.  Talk about a busy day!  I would like to thank everyone for attending today’s event and to all of our sponsors.  Boise Code Camp is a free event to attend, but it is not free to host.</p>
<p>For those of you who attended my session you can download the <a href="http://brianlagunas.com/downloads/presentations/ncc2012/wpfcustomcontrols.zip">source code here</a>.</p>
<p>Thanks again to everyone!  See you next year.</p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/03/24/boise-code-camp-2012-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Silverlight 5 Static Markup Extension</title>
		<link>http://brianlagunas.com/2012/03/23/creating-a-silverlight-5-static-markup-extension/</link>
		<comments>http://brianlagunas.com/2012/03/23/creating-a-silverlight-5-static-markup-extension/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 19:26:42 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=621</guid>
		<description><![CDATA[If you have done any WPF application development I am sure you have used and fallen in love with the Static markup extension.&#160; If you’re are not familiar with it, the Static markup extension allows you to reference static fields and properties in your XAML markup. For example; let’s assume we have a class with <a href='http://brianlagunas.com/2012/03/23/creating-a-silverlight-5-static-markup-extension/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>If you have done any WPF application development I am sure you have used and fallen in love with the <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.staticextension.aspx" target="_blank">Static</a> markup extension.&#160; If you’re are not familiar with it, the Static markup extension allows you to reference static fields and properties in your XAML markup.</p>
<p>For example; let’s assume we have a class with the following static field defined:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f06b331d-d1ab-4fcb-be78-fef49794452d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Common</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">string</span> StaticText = <span style="color:#a31515">&quot;This is text from a static property&quot;</span>;<br /> }</div>
</p></div>
</p></div>
<p>We can use this field in our WPF application as follows:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a24ace93-5399-4aff-9d73-f414de3bc113" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span><br />     <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">x</span><span style="color:#0000ff">:</span><span style="color:#a31515">Static</span><span style="color:#ff0000"> ext</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Common</span><span style="color:#0000ff">.StaticText}&quot; /&gt;</span><br /> <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></div>
</p></div>
</p></div>
<p><a href="http://brianlagunas.com/wp-content/uploads/2012/03/image9.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://brianlagunas.com/wp-content/uploads/2012/03/image_thumb9.png" width="308" height="194" /></a></p>
<p><em>NOTE: “ext” is a namespace that has been defined to instruct the XAML parser where to find our static field.</em></p>
<p>Pretty cool right?&#160; Unfortunately if you are also doing any Silverlight development you will soon find that this wonderful and useful extension does <strong>NOT</strong> exist in Silverlight.&#160; Luckily for us in Silverlight 5 we were given the ability to write our own custom markup extensions.&#160; This can be done using either the <a href="http://msdn.microsoft.com/en-us/library/gg712747(v=vs.95).aspx" target="_blank">IMarkupExtension</a> or the abstract <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.markupextension(v=vs.95).aspx" target="_blank">MarkupExtension</a> class.</p>
<p>Now it’s time to create our own Static markup extension.&#160; I want to point out that there is a naming convention when creating custom markup extensions.&#160; The convention is as follows; <strong>ExtensionName</strong>Extension.&#160; The name of the extension is followed by Extension.&#160; This is very similar to how you create attributes.&#160; You won’t actually be using the suffix when define them in XAML.</p>
<p>Let’s start by creating a new class called StaticExtension.&#160; The StaticExtension class should derive from the MarkupExtension abstract class.&#160; You will need to implement the abstract ProvideValue method.&#160; The code I used for the Static markup extension is as follows.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9102dc2c-5889-4aa4-beef-d9e088530fcc" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span><br /> <span style="color:#808080">///</span><span style="color:#008000">  Class for Xaml markup extension for static field and property references.</span><br /> <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span><span style="color:#008000"> </span><br /> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">StaticExtension</span> : <span style="color:#2b91af">MarkupExtension</span><br /> {<br />     <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span><br />     <span style="color:#808080">///</span><span style="color:#008000">  The static field or property represented by a string.  This string is</span><br />     <span style="color:#808080">///</span><span style="color:#008000">  of the format Prefix:ClassName.FieldOrPropertyName.  The Prefix is </span><br />     <span style="color:#808080">///</span><span style="color:#008000">  optional, and refers to the XML prefix in a Xaml file.</span><br />     <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span><span style="color:#008000"> </span><br />     <span style="color:#0000ff">private</span> <span style="color:#0000ff">string</span> _member;<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Member<br />     {<br />         <span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> _member; }<br />         <span style="color:#0000ff">set</span><br />         {<br />             <span style="color:#0000ff">if</span> (<span style="color:#0000ff">value</span> == <span style="color:#0000ff">null</span>)<br />             {<br />                 <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">ArgumentNullException</span>(<span style="color:#a31515">&quot;Member&quot;</span>);<br />             }<br />             _member = <span style="color:#0000ff">value</span>;<br />         }<br />     }</p>
<p>     <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span><br />     <span style="color:#808080">///</span><span style="color:#008000">  Return an object that should be set on the targetObject&#39;s targetProperty </span><br />     <span style="color:#808080">///</span><span style="color:#008000">  for this markup extension.  For a StaticExtension this is a static field </span><br />     <span style="color:#808080">///</span><span style="color:#008000">  or property value.</span><br />     <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span><span style="color:#008000"> </span><br />     <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;serviceProvider&quot;&gt;</span><span style="color:#008000">Object that can provide services for the markup extension.</span><br />     <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;returns&gt;</span><br />     <span style="color:#808080">///</span><span style="color:#008000">  The object to set on this property.</span><br />     <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/returns&gt;</span><span style="color:#008000"> </span><br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">object</span> ProvideValue(<span style="color:#2b91af">IServiceProvider</span> serviceProvider)<br />     {<br />         <span style="color:#0000ff">if</span> (_member == <span style="color:#0000ff">null</span>)<br />             <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">InvalidOperationException</span>(<span style="color:#a31515">&quot;member cannot be null&quot;</span>);</p>
<p>         <span style="color:#008000">// Validate the _member </span><br />         <span style="color:#0000ff">int</span> dotIndex = _member.IndexOf(<span style="color:#a31515">&#39;.&#39;</span>);<br />         <span style="color:#0000ff">if</span> (dotIndex &lt; 0)<br />             <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">ArgumentException</span>(<span style="color:#a31515">&quot;dotIndex&quot;</span>);</p>
<p>         <span style="color:#008000">// Pull out the type substring (this will include any XML prefix, e.g. &quot;av:Button&quot;) </span><br />         <span style="color:#0000ff">string</span> typeString = _member.Substring(0, dotIndex);<br />         <span style="color:#0000ff">if</span> (typeString == <span style="color:#0000ff">string</span>.Empty)<br />             <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">ArgumentException</span>(<span style="color:#a31515">&quot;typeString&quot;</span>);</p>
<p>         <span style="color:#008000">// Get the IXamlTypeResolver from the service provider</span><br />         <span style="color:#2b91af">IXamlTypeResolver</span> xamlTypeResolver = serviceProvider.GetService(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">IXamlTypeResolver</span>)) <span style="color:#0000ff">as</span> <span style="color:#2b91af">IXamlTypeResolver</span>;<br />         <span style="color:#0000ff">if</span> (xamlTypeResolver == <span style="color:#0000ff">null</span>)<br />             <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">ArgumentException</span>(<span style="color:#a31515">&quot;xamlTypeResolver&quot;</span>);</p>
<p>         <span style="color:#008000">// Use the type resolver to get a Type instance </span><br />         <span style="color:#2b91af">Type</span> type = xamlTypeResolver.Resolve(typeString);</p>
<p>         <span style="color:#008000">// Get the member name substring</span><br />         <span style="color:#0000ff">string</span> fieldString = _member.Substring(dotIndex + 1, _member.Length &#8211; dotIndex &#8211; 1);<br />         <span style="color:#0000ff">if</span> (fieldString == <span style="color:#0000ff">string</span>.Empty)<br />             <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">ArgumentException</span>(<span style="color:#a31515">&quot;fieldString&quot;</span>);</p>
<p>         <span style="color:#008000">// Use the built-in parser for enum types</span><br />         <span style="color:#0000ff">if</span> (type.IsEnum)<br />         {<br />             <span style="color:#0000ff">return</span> <span style="color:#2b91af">Enum</span>.Parse(type, fieldString, <span style="color:#0000ff">true</span>);<br />         }</p>
<p>         <span style="color:#008000">// For other types, reflect </span><br />         <span style="color:#0000ff">bool</span> found = <span style="color:#0000ff">false</span>;<br />         <span style="color:#0000ff">object</span> value = <span style="color:#0000ff">null</span>;</p>
<p>         <span style="color:#0000ff">object</span> fieldOrProp = type.GetField(fieldString, <span style="color:#2b91af">BindingFlags</span>.Public |<br />                                                         <span style="color:#2b91af">BindingFlags</span>.FlattenHierarchy | <span style="color:#2b91af">BindingFlags</span>.Static);<br />         <span style="color:#0000ff">if</span> (fieldOrProp == <span style="color:#0000ff">null</span>)<br />         {<br />             fieldOrProp = type.GetProperty(fieldString, <span style="color:#2b91af">BindingFlags</span>.Public |<br />                                                         <span style="color:#2b91af">BindingFlags</span>.FlattenHierarchy | <span style="color:#2b91af">BindingFlags</span>.Static);<br />             <span style="color:#0000ff">if</span> (fieldOrProp <span style="color:#0000ff">is</span> <span style="color:#2b91af">PropertyInfo</span>)<br />             {<br />                 value = ((<span style="color:#2b91af">PropertyInfo</span>)fieldOrProp).GetValue(<span style="color:#0000ff">null</span>, <span style="color:#0000ff">null</span>);<br />                 found = <span style="color:#0000ff">true</span>;<br />             }<br />         }<br />         <span style="color:#0000ff">else</span> <span style="color:#0000ff">if</span> (fieldOrProp <span style="color:#0000ff">is</span> <span style="color:#2b91af">FieldInfo</span>)<br />         {<br />             value = ((<span style="color:#2b91af">FieldInfo</span>)fieldOrProp).GetValue(<span style="color:#0000ff">null</span>);<br />             found = <span style="color:#0000ff">true</span>;<br />         }</p>
<p>         <span style="color:#0000ff">if</span> (found)<br />             <span style="color:#0000ff">return</span> value;<br />         <span style="color:#0000ff">else</span><br />             <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">ArgumentException</span>(<span style="color:#a31515">&quot;not found&quot;</span>);<br />     }<br /> }</div>
</p></div>
</p></div>
<p>Now all I need to do is add a namespace to my Silverlight view and then use it in XAML as follows:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6664b452-741b-469a-bca6-be32ae3e1926" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">=&quot;LayoutRoot&quot;</span><span style="color:#ff0000"> Background</span><span style="color:#0000ff">=&quot;White&quot;&gt;</span><br />     <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">ext</span><span style="color:#0000ff">:</span><span style="color:#a31515">Static</span><span style="color:#ff0000"> Member</span><span style="color:#0000ff">=ext:Common.StaticText}&quot; /&gt;</span><br /> <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span></div>
</p></div>
</p></div>
<p><a href="http://brianlagunas.com/wp-content/uploads/2012/03/image10.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://brianlagunas.com/wp-content/uploads/2012/03/image_thumb10.png" width="430" height="260" /></a></p>
<p>That’s it!&#160; I will definitely be using this quite often.&#160; I would like to mention that unlike in WPF where you don’t have to specify the “Member” property explicitly, in Silveright you have to explicitly set the Member property.&#160; This is because there is not a <a href="http://msdn.microsoft.com/en-us/library/system.workflow.componentmodel.serialization.constructorargumentattribute.aspx" target="_blank">ConstructorArgument</a> attribute in Silverlight.&#160; So until then you will need to have a little extra text in your markup syntax.</p>
<p><a href="http://brianlagunas.com/downloads/source/SilverlightStaticMarkupExtension.zip" target="_blank">Download the source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/03/23/creating-a-silverlight-5-static-markup-extension/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Nebraska Code Camp 2012 Sample code</title>
		<link>http://brianlagunas.com/2012/03/22/nebraska-code-camp-2012-sample-code/</link>
		<comments>http://brianlagunas.com/2012/03/22/nebraska-code-camp-2012-sample-code/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 22:04:35 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Code Camps]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Nebraska Code Camp]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/?p=598</guid>
		<description><![CDATA[Obviously I am extremely late posing this, but being a PM is rather time consuming.  First off, I would like to thank everyone who attended my sessions.  A lucky few of you even won an awesome subscription to Infragistics NetAdvantage Ultimate toolset.  I hope you will show me the great applications you will be building <a href='http://brianlagunas.com/2012/03/22/nebraska-code-camp-2012-sample-code/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Obviously I am extremely late posing this, but being a PM is rather time consuming.  First off, I would like to thank everyone who attended my sessions.  A lucky few of you even won an awesome subscription to <a href="http://www.infragistics.com/" target="_blank">Infragistics</a> NetAdvantage Ultimate toolset.  I hope you will show me the great applications you will be building with it.  Preferably XAML based apps :0).</p>
<p>Now what you have been waiting for:</p>
<p><a href="http://brianlagunas.com/downloads/presentations/ncc2012/prismdemos.zip">Introduction to Prism sample code</a></p>
<p><a href="http://brianlagunas.com/downloads/presentations/ncc2012/wpfcustomcontrols.zip">Introduction to WPF Custom Controls sample code</a></p>
<p>If you have any questions or need a better explanation about a specific topic be sure to let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://brianlagunas.com/2012/03/22/nebraska-code-camp-2012-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

