<?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>Abhishek Shukla &#187; Expression Blend</title>
	<atom:link href="http://www.abhishekshukla.com/category/expression-suite/expression-blend/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.abhishekshukla.com</link>
	<description>This is one stop shop for technology and gadget information</description>
	<lastBuildDate>Wed, 22 May 2013 11:09:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Expression Blend 4 : User Controls</title>
		<link>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-user-controls/</link>
		<comments>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-user-controls/#comments</comments>
		<pubDate>Tue, 03 Jul 2012 11:50:23 +0000</pubDate>
		<dc:creator>Abhishek</dc:creator>
				<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Expression Blend 4]]></category>
		<category><![CDATA[User Controls]]></category>

		<guid isPermaLink="false">http://www.abhishekshukla.com/?p=3018</guid>
		<description><![CDATA[&#160; In this section we will see how we can break our pages into small pieces by the use of User Controls. If you have worked even once on Silverlight you will see that UserControl is the root Element. So whenever a Silverlight application is displayed in a browser then the first thing that a [...]]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/171.png" width="240" title="Expression Blend 4 : User Controls" alt="171 Expression Blend 4 : User Controls" />
		</p><p>&nbsp;</p>
<p>In this section we will see how we can break our pages into small pieces by the use of User Controls. If you have worked even once on Silverlight you will see that UserControl is the root Element. So whenever a Silverlight application is displayed in a browser then the first thing that a browser does instantiates the Root UserControl of the start page of the Silverlight application. A User Control can have any number of layout containers in it, it has its own code behind and has an entire system that builds an application. This is concept is extended by Silverlight by moving the pieces of the user control and moving them to the individual documents.</p>
<ul>
<li>Create a new Silverlight application Expression Blend.  In the UserControl add 4 girds and in each grid add a rectangle and give that rectangle a different fill from the others.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3019" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/110.png"><img class="size-medium wp-image-3019" title="Expression Blend 4 : Grids" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/110-300x93.png" alt="110 300x93 Expression Blend 4 : User Controls" width="300" height="93" /></a><p class="wp-caption-text">Expression Blend 4 : Grids</p></div>
<ul>
<li>Now right click on the 1<sup>st</sup> grid and select Make Into User Control. Build the solution.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3020" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/210.png"><img class="size-medium wp-image-3020" title="Expression Blend 4 : User Control" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/210-300x166.png" alt="210 300x166 Expression Blend 4 : User Controls" width="300" height="166" /></a><p class="wp-caption-text">Expression Blend 4 : User Control</p></div>
<ul>
<li>We will see that the our application MainPage is still the samebut if we see the Objects and timeline the grid that we converted to User Control is replaced the UserControl. Also we will see and exclamation mark. Once we build our project it goes away.</li>
<li>Now if we go and change something in the user control we will see that the change is appearing in the MainPage but with and exclamation mark stating that something has changed.</li>
<li>But you may need to pay attention when you are working with resources and user Controls. Let me tell you what exactly I am talking about. Just Select a TextBlock and drag it onto the Blue Rectangle.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3021" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/310.png"><img class="size-medium wp-image-3021" title="Expression Blend 4 : Text Blocks" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/310-300x123.png" alt="310 300x123 Expression Blend 4 : User Controls" width="300" height="123" /></a><p class="wp-caption-text">Expression Blend 4 : Text Blocks</p></div>
<ul>
<li>Type some text into the textblock. Come out of the edit mode by pressing ctrl + Enter. Now scroll down to the Text properties of the TextBlock and select the Font as Broadway and Font Size as 20 pt.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3022" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/42.png"><img class="size-medium wp-image-3022" title="Expression Blend 4 : Font Family" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/42-300x175.png" alt="42 300x175 Expression Blend 4 : User Controls" width="300" height="175" /></a><p class="wp-caption-text">Expression Blend 4 : Font Family</p></div>
<ul>
<li>Now click on the property marker next to the Font Family and select Convert to new resource. Name it as MyFont.</li>
</ul>
<div id="attachment_3023" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/51.png"><img class="size-medium wp-image-3023" title="Expression Blend 4 : Font Family Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/51-300x162.png" alt="51 300x162 Expression Blend 4 : User Controls" width="300" height="162" /></a><p class="wp-caption-text">Expression Blend 4 : Font Family Resource</p></div>
<p>&nbsp;</p>
<ul>
<li>Now let’s go ahead and create another text block in the Green user Control. Now try to use the local resources while the text of the textblock is selected.  We will notice that while we are in edit mode we cannot create or use resources.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3024" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/61.png"><img class="size-medium wp-image-3024" title="Expression Blend 4 : Font Family Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/61-300x239.png" alt="61 300x239 Expression Blend 4 : User Controls" width="300" height="239" /></a><p class="wp-caption-text">Expression Blend 4 : Font Family Resource</p></div>
<p>&nbsp;</p>
<ul>
<li>Now let come out of the edit mode and select the local resource MyFont to set the font of the Shopping Cart.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3025" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/71.png"><img class="size-medium wp-image-3025" title="Expression Blend 4 : Font Family Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/71-300x223.png" alt="71 300x223 Expression Blend 4 : User Controls" width="300" height="223" /></a><p class="wp-caption-text">Expression Blend 4 : Font Family Resource</p></div>
<ul>
<li>If we place a textblock on the user control and try to use local Resource MyFont than it is not available because we have saved that MyFont as the local resource in the MainPage document.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3026" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/81.png"><img class="size-medium wp-image-3026" title="Expression Blend 4 : Font Family Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/81-300x196.png" alt="81 300x196 Expression Blend 4 : User Controls" width="300" height="196" /></a><p class="wp-caption-text">Expression Blend 4 : Font Family Resource</p></div>
<ul>
<li>Now lets add another text block to the bottom grid and use the local Resource MyFont.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3027" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/91.png"><img class="size-medium wp-image-3027" title="Expression Blend 4 : Local Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/91-300x138.png" alt="91 300x138 Expression Blend 4 : User Controls" width="300" height="138" /></a><p class="wp-caption-text">Expression Blend 4 : Local Resource</p></div>
<ul>
<li>Now let’s make the bottom grid into a user control and now we will see that the Textblock still is using the MyFont resource.</li>
</ul>
<div id="attachment_3028" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/101.png"><img class="size-medium wp-image-3028" title="Expression Blend 4 : Local Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/101-300x77.png" alt="101 300x77 Expression Blend 4 : User Controls" width="300" height="77" /></a><p class="wp-caption-text">Expression Blend 4 : Local Resource</p></div>
<p>&nbsp;</p>
<ul>
<li>Now lets go to the resources tab and expand the UserControl and we will see that the MyFont Resource is present there.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3029" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/111.png"><img class="size-medium wp-image-3029" title="Expression Blend 4 : Local Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/111-300x203.png" alt="111 300x203 Expression Blend 4 : User Controls" width="300" height="203" /></a><p class="wp-caption-text">Expression Blend 4 : Local Resource</p></div>
<ul>
<li>Let’s drag MyFont resource to application level so that all the control can use it.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3030" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/121.png"><img class="size-medium wp-image-3030" title="Expression Blend 4 : Application Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/121-300x191.png" alt="121 300x191 Expression Blend 4 : User Controls" width="300" height="191" /></a><p class="wp-caption-text">Expression Blend 4 : Application Resource</p></div>
<ul>
<li>Now if we go to the top user control and use the MyFont resource.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3031" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/131.png"><img class="size-medium wp-image-3031" title="Expression Blend 4 : Application Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/131-300x106.png" alt="131 300x106 Expression Blend 4 : User Controls" width="300" height="106" /></a><p class="wp-caption-text">Expression Blend 4 : Application Resource</p></div>
<ul>
<li>Let’s say now we have a requirement of changing the font to some other font. That should be easy right. Go to the Resources tab and change the font to Courier New. You will be surprised to see something like below.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3032" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/141.png"><img class="size-medium wp-image-3032" title="Expression Blend 4 : Application Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/141-300x188.png" alt="141 300x188 Expression Blend 4 : User Controls" width="300" height="188" /></a><p class="wp-caption-text">Expression Blend 4 : Application Resource</p></div>
<ul>
<li>This is because the at value change the resources might not be updated. So let’s hit ctrl + Shift + B. Still the bottom control is not refreshing.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3033" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/151.png"><img class="size-medium wp-image-3033" title="Expression Blend 4 : Application Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/151-300x226.png" alt="151 300x226 Expression Blend 4 : User Controls" width="300" height="226" /></a><p class="wp-caption-text">Expression Blend 4 : Application Resource</p></div>
<ul>
<li>The reason is that when we converted that grid into a User Control it realized that it is referring a resource that it will not have access to when it is converted to a User Control so what it did was created a resource named MyFont in the user Control itself. We can see we navigate to the resource of the userControl2.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3034" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/161.png"><img class="size-medium wp-image-3034" title="Expression Blend 4 : Application Resource" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/161-300x119.png" alt="161 300x119 Expression Blend 4 : User Controls" width="300" height="119" /></a><p class="wp-caption-text">Expression Blend 4 : Application Resource</p></div>
<ul>
<li>So let’s delete the resource of the UserControl then we will get a  message like below. So we will select don’t fix and so the UserControl will still be using the MyFont and will refer the application level resource.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3035" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/171.png"><img class="size-medium wp-image-3035" title="Expression Blend 4 : Existing References Found" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/171-300x207.png" alt="171 300x207 Expression Blend 4 : User Controls" width="300" height="207" /></a><p class="wp-caption-text">Expression Blend 4 : Existing References Found</p></div>
<ul>
<li>Now when you build the application everything should be fine.</li>
</ul>
<p>The code this post can be found <a target="_blank" href="http://i.minus.com/1341402584/ynLj5fUMOZ9E7hI7KIFFdg/dqVc79vbO2lsF/UserControlSample.zip">here</a>.</p>
<p>&nbsp;</p>
<p>Any questions, comments or feedback is most welcome.</p>
<div style="min-height:33px;" class="really_simple_share really_simple_share_button robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;"><iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.abhishekshukla.com%2Fexpression-suite%2Fexpression-blend%2Fexpression-blend-4-user-controls%2F&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=27&amp;locale=en_US" 
							scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe></div><div class="really_simple_share_twitter" style="width:100px;"><a target="_blank" href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Expression Blend 4 : User Controls" data-url="http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-user-controls/" 
						data-via=""  ></a></div><div class="really_simple_share_google1" style="width:80px;"><div class="g-plusone" data-size="medium" data-href="http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-user-controls/" ></div></div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-user-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding</title>
		<link>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-data-binding-element-data-binding-data-source-data-binding/</link>
		<comments>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-data-binding-element-data-binding-data-source-data-binding/#comments</comments>
		<pubDate>Mon, 02 Jul 2012 11:38:50 +0000</pubDate>
		<dc:creator>Abhishek</dc:creator>
				<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[Data Source Data Binding]]></category>
		<category><![CDATA[Element Data Binding]]></category>
		<category><![CDATA[Expression Blend 4]]></category>
		<category><![CDATA[one way]]></category>
		<category><![CDATA[two way]]></category>

		<guid isPermaLink="false">http://www.abhishekshukla.com/?p=2973</guid>
		<description><![CDATA[&#160; Working with Data in Expression Blend 4 Element to Element Data Binding In this section we are going to see how we can use data binding in Expression Blend. We will see how we can create sample data sources and how to use them in data binding. Data binding is a functionality that both [...]]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/41.png" width="240" title="Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" alt="41 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" />
		</p><p>&nbsp;</p>
<h1>Working with Data in Expression Blend 4</h1>
<h2>Element to Element Data Binding</h2>
<p>In this section we are going to see how we can use data binding in Expression Blend. We will see how we can create sample data sources and how to use them in data binding.</p>
<p>Data binding is a functionality that both Silverlight and WPF have that helps us set the property of an element to an external data source. That data source can be xml if we are using WPF and can be any CLR object if we are using Silverlight or WPF. It could also be a sample data source. When we apply data binding to an element then that element does not get its value directly but it has to go to some other location for getting its value. This other location can be another element or a database or an xml.</p>
<ul>
<li>Let’s have a look at the element to element data binding. Open Expression blend 4 and create a new Silverlight Project.</li>
<li>Now go to the tools pallet and select rectangle.</li>
</ul>
<div id="attachment_2974" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/1.png"><img class="size-medium wp-image-2974" title="Expression Blend 4 : Rectangle" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/1-300x270.png" alt="1 300x270 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="270" /></a><p class="wp-caption-text">Expression Blend 4 : Rectangle</p></div>
<ul>
<li>Now create a rectangle by pressing the left button of the mouse and dragging it on the artboard.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2975" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/2.png"><img class="size-medium wp-image-2975" title="Expression Blend 4 : Rectangle" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/2-300x240.png" alt="2 300x240 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="240" /></a><p class="wp-caption-text">Expression Blend 4 : Rectangle</p></div>
<ul>
<li>Now go to the properties of the rectangle and set the horizontal alignment to stretch and left and right margins to 0.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2976" class="wp-caption alignnone" style="width: 272px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/3.png"><img class="size-full wp-image-2976" title="Expression Blend 4 : Rectangle Properties" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/3.png" alt="3 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="262" height="247" /></a><p class="wp-caption-text">Expression Blend 4 : Rectangle Properties</p></div>
<ul>
<li>Let’s go back to the tools pane and grab a slider and drop it on the artboard.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2977" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/4.png"><img class="size-medium wp-image-2977" title="Expression Blend 4 : Slider" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/4-300x133.png" alt="4 300x133 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="133" /></a><p class="wp-caption-text">Expression Blend 4 : Slider</p></div>
<ul>
<li>If you have a look at the properties of the slider you would see values like Maximum (The maximum value of the slider), Minimum (the minimum value of a slider), SmallChange (the value that will change when user has focused the slider and uses the up and down arrow key to change the value of the slider), LargeChange (the value that will change when do a mouse click at any location on the slider track). Let’s set these properties as shown below.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2978" class="wp-caption alignnone" style="width: 272px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/5.png"><img class="size-full wp-image-2978" title="Expression Blend 4 : Slider Properties" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/5.png" alt="5 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="262" height="296" /></a><p class="wp-caption-text">Expression Blend 4 : Slider Properties</p></div>
<ul>
<li>Now let’s setup the data binding. There are two ways to set the data binding: one way or two way. In one way data binding only one property can change the other but not vice versa. In two way data binding both the properties can change each other. In this case we want only one way binding so that the width of the rectangle can change on the change in the slider. So let’s select the rectangle and go to the width property and click on the property marker next to it.</li>
</ul>
<div id="attachment_2979" class="wp-caption alignnone" style="width: 281px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/6.png"><img class="size-full wp-image-2979" title="Expression Blend 4 : Rectangle Property Marker" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/6.png" alt="6 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="271" height="80" /></a><p class="wp-caption-text">Expression Blend 4 : Rectangle Property Marker</p></div>
<p>&nbsp;</p>
<ul>
<li>And select element property binding.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2980" class="wp-caption alignnone" style="width: 199px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/7.png"><img class="size-medium wp-image-2980" title="Expression Blend 4 : Element Property Binding" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/7-189x300.png" alt="7 189x300 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="189" height="300" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding</p></div>
<ul>
<li>Now our cursor has been moved to the object picker mode so we need to point to the element with which we want to do the property binding. In this case we will move our cursor to the slider and click on the slider.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2981" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/8.png"><img class="size-medium wp-image-2981" title="Expression Blend 4 : Element Property Binding" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/8-300x71.png" alt="8 300x71 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="71" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding</p></div>
<ul>
<li>Once we will click on the slider we will get an option select which property of the slider we want to bind to and we will select value.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2982" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/9.png"><img class="size-medium wp-image-2982" title="Expression Blend 4 : Element Property Binding" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/9-300x282.png" alt="9 300x282 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="282" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding</p></div>
<ul>
<li>The moment we do this we see that the width of the rectangle is changed and the Width property has a yellow rectangle around it showing that this property is getting its value from some other location.</li>
</ul>
<div id="attachment_2983" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/10.png"><img class="size-medium wp-image-2983" title="Expression Blend 4 : Element Property Binding" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/10-300x163.png" alt="10 300x163 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="163" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding</p></div>
<p>&nbsp;</p>
<ul>
<li>Now we can run the application and see that the width of the rectangle will change as we change the slider value.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2984" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/11.png"><img class="size-medium wp-image-2984" title="Expression Blend 4 : Element Property Binding" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/11-300x266.png" alt="11 300x266 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="266" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding</p></div>
<h2>Two Way Data Binding</h2>
<p>In this section we will see how we can create two way data binding. Along with the Slider we will provide a textbox to modify the width of the rectangle.</p>
<ul>
<li>Let’s drag out a textbox on to the artboard.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2985" class="wp-caption alignnone" style="width: 279px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/12.png"><img class="size-medium wp-image-2985" title="Expression Blend 4 : Element Property Binding Two Way" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/12-269x300.png" alt="12 269x300 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="269" height="300" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding Two Way</p></div>
<ul>
<li>Now go to the text property of the textbox and click on the property marker and select Element Property Binding.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2986" class="wp-caption alignnone" style="width: 229px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/13.png"><img class="size-medium wp-image-2986" title="Expression Blend 4 : Element Property Binding Two Way" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/13-219x300.png" alt="13 219x300 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="219" height="300" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding Two Way</p></div>
<ul>
<li>Select the slider control again and select its value property again as we did in the case of the rectangle. Also we will select the TwoWay Binding so that both the controls i.e. TextBox and Slider can change each other’s value.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2987" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/14.png"><img class="size-medium wp-image-2987" title="Expression Blend 4 : Element Property Binding Two Way" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/14-300x257.png" alt="14 300x257 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="257" /></a><p class="wp-caption-text">Expression Blend 4 : Element Property Binding Two Way</p></div>
<ul>
<li>Now we can run the application and change the value of the slider or textbox and we will see that the width of the rectangle is changing and the other control’s value is also updated.</li>
</ul>
<h2>Data Binding with Data Sources</h2>
<p>&nbsp;</p>
<p>In this section we will see how we can use data binding with data sources. Data sources can either be xml or any other CLR object. As we know that xml works only with WPF so for this demo we will have to use data binding with sample data. When we work on an actual project we have CLR objects in which data is stored and they definitely follow some schema. So we can build up sample data in Blend to represent that sample data. So let’s get started.</p>
<ul>
<li>Create a new project in Blend. Navigate to the data tab in the right panel. If the data tab is not visible then goto the window menu of blend and select data.</li>
</ul>
<div id="attachment_2990" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/15.png"><img class="size-medium wp-image-2990" title="Expression Blend 4 : Data" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/15-300x80.png" alt="15 300x80 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="80" /></a><p class="wp-caption-text">Expression Blend 4 : Data</p></div>
<ul>
<li>Click on the Create Data Source.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2991" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/16.png"><img class="size-medium wp-image-2991" title="Expression Blend 4 : Create Data Source" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/16-300x108.png" alt="16 300x108 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="108" /></a><p class="wp-caption-text">Expression Blend 4 : Create Data Source</p></div>
<ul>
<li>And select New Sample Data. You will also see option to create Sample data using XML or Class. If we have those then we can use them. When we select any of those two options then blend will not exactly use those but take them as a basis for generating sample data.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2992" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/17.png"><img class="size-medium wp-image-2992" title="Expression Blend 4 : Add new Sample Data" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/17-300x120.png" alt="17 300x120 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="120" /></a><p class="wp-caption-text">Expression Blend 4 : Add new Sample Data</p></div>
<ul>
<li>Give the Sample Data Source some name and select the define in as project. We do want to enable sample data when application is running so keep It checked.</li>
</ul>
<div id="attachment_2993" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/18.png"><img class="size-medium wp-image-2993" title="Expression Blend 4 : Add new Sample Data" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/18-300x158.png" alt="18 300x158 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="158" /></a><p class="wp-caption-text">Expression Blend 4 : Add new Sample Data</p></div>
<p>&nbsp;</p>
<ul>
<li>When we click ok we will see that the data source appears in the data tab at project level and we have a collection with properties in it.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2994" class="wp-caption alignnone" style="width: 296px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/19.png"><img class="size-full wp-image-2994" title="Expression Blend 4 : Sample Data" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/19.png" alt="19 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="286" height="261" /></a><p class="wp-caption-text">Expression Blend 4 : Sample Data</p></div>
<ul>
<li>We can also see that in the Projects that a new folder is added named SampleData. When we expand it we see that there is a xaml in it which will store all the data and an xsd which is the schema.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2995" class="wp-caption alignnone" style="width: 247px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/20.png"><img class="size-medium wp-image-2995" title="Expression Blend 4 : Sample Data Folder" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/20-237x300.png" alt="20 237x300 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="237" height="300" /></a><p class="wp-caption-text">Expression Blend 4 : Sample Data Folder</p></div>
<ul>
<li>If we open the MyAddresses.xaml, we will see that we have some items already added in the data source. We modify their values or add new items.</li>
</ul>
<div id="attachment_2996" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/21.png"><img class="size-medium wp-image-2996" title="Expression Blend 4 : Sample Data xaml" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/21-300x182.png" alt="21 300x182 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="182" /></a><p class="wp-caption-text">Expression Blend 4 : Sample Data xaml</p></div>
<p>&nbsp;</p>
<ul>
<li>Let’s go back to the data tab and click on Edit Sample Values as shown in the image below.</li>
</ul>
<div id="attachment_2997" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/22.png"><img class="size-medium wp-image-2997" title="Expression Blend 4 : Edit Sample Data" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/22-300x176.png" alt="22 300x176 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="176" /></a><p class="wp-caption-text">Expression Blend 4 : Edit Sample Data</p></div>
<p>&nbsp;</p>
<ul>
<li>We will see something like below. We can edit the values or the types of these properties.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_2998" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/23.png"><img class="size-medium wp-image-2998" title="Expression Blend 4 : Edit Sample Data" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/23-300x215.png" alt="23 300x215 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="215" /></a><p class="wp-caption-text">Expression Blend 4 : Edit Sample Data</p></div>
<ul>
<li>Let’s rename the properties as shown below. Also lets change the specification of the Address property as shown below.</li>
</ul>
<div id="attachment_2999" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/24.png"><img class="size-medium wp-image-2999" title="Expression Blend 4 : Edit Sample Data Property Type and Format" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/24-300x132.png" alt="24 300x132 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="132" /></a><p class="wp-caption-text">Expression Blend 4 : Edit Sample Data Property Type and Format</p></div>
<p>&nbsp;</p>
<ul>
<li>Also similarly change the Format of name to Name. When we do that if you go back to Edit Values we will see that the data is has been populated according to the format selected.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3000" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/25.png"><img class="size-medium wp-image-3000" title="Expression Blend 4 : Edit Sample Values" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/25-300x197.png" alt="25 300x197 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="197" /></a><p class="wp-caption-text">Expression Blend 4 : Edit Sample Values</p></div>
<ul>
<li>Let’s add email, phone number  and CustomColor properties.Also modify the format accordingly</li>
</ul>
<div id="attachment_3001" class="wp-caption alignnone" style="width: 306px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/26.png"><img class="size-medium wp-image-3001" title="Expression Blend 4 : Edit Sample Values Format" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/26-296x300.png" alt="26 296x300 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="296" height="300" /></a><p class="wp-caption-text">Expression Blend 4 : Edit Sample Values Format</p></div>
<p>&nbsp;</p>
<ul>
<li>And we will see data something like below.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3002" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/27.png"><img class="size-medium wp-image-3002" title="Expression Blend 4 : Add Properties in Sample Values" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/27-300x207.png" alt="27 300x207 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="207" /></a><p class="wp-caption-text">Expression Blend 4 : Add Properties in Sample Values</p></div>
<ul>
<li>Now let’s start using this data that we have created. Drag and drop the Collection onto the artboard.</li>
</ul>
<div id="attachment_3003" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/28.png"><img class="size-medium wp-image-3003" title="Expression Blend 4 : Create Databound ListBox" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/28-300x165.png" alt="28 300x165 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="165" /></a><p class="wp-caption-text">Expression Blend 4 : Create Databound ListBox</p></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ul>
<li>And a listbox will be automatically created. And each entry will show all the fields. Also the yellow rectangle around the datasource shows data binding.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3004" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/29.png"><img class="size-medium wp-image-3004" title="Expression Blend 4 : Create Databound ListBox" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/29-300x277.png" alt="29 300x277 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="277" /></a><p class="wp-caption-text">Expression Blend 4 : Create Databound ListBox</p></div>
<ul>
<li>Let’s improve the look of the List Box by the use of Data Template. Right Click the ListBox and Go to Edit Additional Template à Edit Generated Items (ItemTemplate) à Edit Current</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3005" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/30.png"><img class="size-medium wp-image-3005" title="Expression Blend 4 : Edit Generated Items " src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/30-300x237.png" alt="30 300x237 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="237" /></a><p class="wp-caption-text">Expression Blend 4 : Edit Generated Items</p></div>
<ul>
<li>We would something like this. Let’s delete the Color textblock as we do not want to display the color in this way. When we delete that textblock you would see that that textblock is deleted from each item and that’s the way templates work.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3006" class="wp-caption alignnone" style="width: 247px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/31.png"><img class="size-medium wp-image-3006" title="Expression Blend 4 : ListBox DataTemplate" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/31-237x300.png" alt="31 237x300 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="237" height="300" /></a><p class="wp-caption-text">Expression Blend 4 : ListBox DataTemplate</p></div>
<ul>
<li>Now let’s select the listbox from the breadcrumb bar and stretch it.</li>
</ul>
<div id="attachment_3007" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/32.png"><img class="size-medium wp-image-3007" title="Expression Blend 4 : ListBox DataTemplate" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/32-300x172.png" alt="32 300x172 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="172" /></a><p class="wp-caption-text">Expression Blend 4 : ListBox DataTemplate</p></div>
<p>&nbsp;</p>
<ul>
<li>Now let’s go back to the template and change the  orientation of the stackpanel to horizontal from vertical. And then build the solution. We will see something like below.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3008" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/33.png"><img class="size-medium wp-image-3008" title="Expression Blend 4 : StackPanel Orientation" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/33-300x67.png" alt="33 300x67 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="67" /></a><p class="wp-caption-text">Expression Blend 4 : StackPanel Orientation</p></div>
<ul>
<li>Lets give specific width to all the textblocks and we will see a clean layout.</li>
</ul>
<div id="attachment_3009" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/34.png"><img class="size-medium wp-image-3009" title="Expression Blend 4 : StackPanel Orientation" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/34-300x148.png" alt="34 300x148 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="148" /></a><p class="wp-caption-text">Expression Blend 4 : StackPanel Orientation</p></div>
<p>&nbsp;</p>
<ul>
<li>Let’s delete all the textblocks except the Name TextBlock. Then let’s go back and select the listbox and reduce its width.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3010" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/35.png"><img class="size-medium wp-image-3010" title="Expression Blend 4 : DataContext" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/35-300x112.png" alt="35 300x112 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="112" /></a><p class="wp-caption-text">Expression Blend 4 : DataContext</p></div>
<ul>
<li>Now go to the data tab and select the view mode to details view.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3011" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/36.png"><img class="size-medium wp-image-3011" title="Expression Blend 4 : DataContext" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/36-300x222.png" alt="36 300x222 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="222" /></a><p class="wp-caption-text">Expression Blend 4 : DataContext</p></div>
<ul>
<li>Now let’s drag the Name field on to the art board. We will see that a grid is created along with textblock as its child. Now whenever we select the item in the listbox we will see that the content of the textblock in the grid is changing. This happens because the grid that got created has a concept called Data Context. The grid has its data context set to the list box. So as soon as an item is selected in listbox then the the value changes in the grid as the items in the grid have already specified what item of the listbox they want to display. We can other fields as well in the grid and see that their value change as the selection of the listbox changed.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3012" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/37.png"><img class="size-medium wp-image-3012" title="Expression Blend 4 : DataContext" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/37-300x101.png" alt="37 300x101 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="101" /></a><p class="wp-caption-text">Expression Blend 4 : DataContext</p></div>
<ul>
<li>When we run the application we will see something like below.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3013" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/38.png"><img class="size-medium wp-image-3013" title="Expression Blend 4 : Run App with Sample Data" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/38-300x231.png" alt="38 300x231 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="231" /></a><p class="wp-caption-text">Expression Blend 4 : Run App with Sample Data</p></div>
<ul>
<li>Lets go to the grid à Background à Property marker à Data Binding. We will a window like below.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3014" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/39.png"><img class="size-medium wp-image-3014" title="Expression Blend 4 : Data Binding Background" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/39-300x248.png" alt="39 300x248 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="248" /></a><p class="wp-caption-text">Expression Blend 4 : Data Binding Background</p></div>
<ul>
<li>Select Customcolor string and the background of the grid is bound to the color string of the selected item. The value conversion is going on in the background.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3015" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/40.png"><img class="size-medium wp-image-3015" title="Expression Blend 4 : Data Binding Background" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/40-300x192.png" alt="40 300x192 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="192" /></a><p class="wp-caption-text">Expression Blend 4 : Data Binding Background</p></div>
<ul>
<li>When we run the application we see something like below.</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_3016" class="wp-caption alignnone" style="width: 310px"><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/07/41.png"><img class="size-medium wp-image-3016" title="Expression Blend 4 : Data Binding Background" src="http://www.abhishekshukla.com/wp-content/uploads/2012/07/41-300x286.png" alt="41 300x286 Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" width="300" height="286" /></a><p class="wp-caption-text">Expression Blend 4 : Data Binding Background</p></div>
<p>The code for this post can be found <a target="_blank" href="http://i.minus.com/1341346399/5YhR2Oas3FcwTJTrFPJuwA/dbnWIcG1nynFlt/ExpBlend4DataBinding.zip">here</a>.</p>
<p>&nbsp;</p>
<p>Any questions, comments or feedback are welcome.</p>
<div style="min-height:33px;" class="really_simple_share really_simple_share_button robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;"><iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.abhishekshukla.com%2Fexpression-suite%2Fexpression-blend%2Fexpression-blend-4-data-binding-element-data-binding-data-source-data-binding%2F&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=27&amp;locale=en_US" 
							scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe></div><div class="really_simple_share_twitter" style="width:100px;"><a target="_blank" href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Expression Blend 4 : Data Binding, Element Data Binding, Data Source Data Binding" data-url="http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-data-binding-element-data-binding-data-source-data-binding/" 
						data-via=""  ></a></div><div class="really_simple_share_google1" style="width:80px;"><div class="g-plusone" data-size="medium" data-href="http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-data-binding-element-data-binding-data-source-data-binding/" ></div></div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blend-4-data-binding-element-data-binding-data-source-data-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expression Blend 4 : Control Customization</title>
		<link>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blen-4-control-customization/</link>
		<comments>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blen-4-control-customization/#comments</comments>
		<pubDate>Tue, 22 May 2012 21:42:34 +0000</pubDate>
		<dc:creator>Abhishek</dc:creator>
				<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Control Cutomization]]></category>
		<category><![CDATA[Control Template]]></category>
		<category><![CDATA[Style]]></category>
		<category><![CDATA[Template Binding]]></category>

		<guid isPermaLink="false">http://www.abhishekshukla.com/?p=2805</guid>
		<description><![CDATA[&#160; Control Customization The whole idea behind WPF architecture was that the presentation layer is completely separate from the functionality. This means a button may look like an image or a circle but still have all the functionality of a button. Custom Controls Create a new project named CustomControls Before we start customizing a control [...]]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls27-1024x424.png" width="240" title="Expression Blend 4 : Control Customization" alt="CustomControls27 1024x424 Expression Blend 4 : Control Customization" />
		</p><p>&nbsp;</p>
<h1>Control Customization</h1>
<p>The whole idea behind WPF architecture was that the presentation layer is completely separate from the functionality. This means a button may look like an image or a circle but still have all the functionality of a button.</p>
<h2>Custom Controls</h2>
<ul>
<li>Create a new project named CustomControls</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls1.png"><img class="alignnone size-medium wp-image-2806" title="CustomControls1" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls1-300x233.png" alt="CustomControls1 300x233 Expression Blend 4 : Control Customization" width="300" height="233" /></a></p>
<ul>
<li>Before we start customizing a control let’s talk about style and template as this will be required for control customization.
<ul>
<li><strong>Styles</strong> – A style is a resource that contains a set of property setters. To see how this works lets create a rectangle on to the design surface. Right click on the rectangle and select Edit Style à Create Empty.</li>
</ul>
</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls2.png"><img class="alignnone size-medium wp-image-2807" title="CustomControls2" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls2-300x247.png" alt="CustomControls2 300x247 Expression Blend 4 : Control Customization" width="300" height="247" /></a></p>
<ul>
<li>Give the style a name and select its location and click on okay</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls3.png"><img class="alignnone size-medium wp-image-2808" title="CustomControls3" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls3-300x234.png" alt="CustomControls3 300x234 Expression Blend 4 : Control Customization" width="300" height="234" /></a></p>
<ol>
<li>The left breadcrumb shows the Layout Root. As we are working with a rectangle we see a rectangle here</li>
<li>The next breadcrumb shows us that we are working with Style. This is represented by an icon that looks like a painter’s palette.</li>
<li>The scope that we are working on has changed to RectangleStyle and the name of the style is RectangleStyle1.</li>
<li>We see only one element as of now which is the style.</li>
<li>All asset creation tools have greyed out as when we work in a style we are restricted to the property of that element which is a rectangle in this case.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls4.png"><img class="alignnone size-medium wp-image-2809" title="CustomControls4" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls4-300x168.png" alt="CustomControls4 300x168 Expression Blend 4 : Control Customization" width="300" height="168" /></a></p>
<ul>
<li>Now let us set some the properties of the rectangle which we will be able to see in the style later on. The properties that are changed are highlighted as red.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls5.png"><img class="alignnone size-medium wp-image-2810" title="CustomControls5" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls5-300x151.png" alt="CustomControls5 300x151 Expression Blend 4 : Control Customization" width="300" height="151" /></a></p>
<ul>
<li>Now let us switch to the XAML of the style and we could see a set of setters as a part of the style of the rectangle which contains the name of the property of the rectangle and its value. Also it has a target type which would specify as to which Element type to target to. You can also see how the rectangle refers the style.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls6.png"><img class="alignnone size-medium wp-image-2811" title="CustomControls6" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls6-300x171.png" alt="CustomControls6 300x171 Expression Blend 4 : Control Customization" width="300" height="171" /></a></p>
<ul>
<li>Now just click on the Rectangle in the Breadcrum bar to go back to the Root Document.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls7.png"><img class="alignnone size-full wp-image-2812" title="CustomControls7" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls7.png" alt="CustomControls7 Expression Blend 4 : Control Customization" width="160" height="110" /></a></p>
<ul>
<li>When we right click on the rectangle,we would see option to Edit the current style of the rectangle or edit a copy that style or create a completely new style or apply resource which can be any other style already created.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls8.png"><img class="alignnone size-medium wp-image-2813" title="CustomControls8" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls8-300x276.png" alt="CustomControls8 300x276 Expression Blend 4 : Control Customization" width="300" height="276" /></a></p>
<ul>
<li>Now just create a rectangle onto the design surface and you would see that the Fill is not set for the rectangle the way it is when create a rectangle by default the reason is that blend expects you apply a style to this rectangle as the last rectangle you were working with had a style. So just right click the rectangle and go to Apply resource and select RectangleStyle1.</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls9.png"><img class="alignnone size-medium wp-image-2814" title="CustomControls9" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls9-300x219.png" alt="CustomControls9 300x219 Expression Blend 4 : Control Customization" width="300" height="219" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls10.png"><img class="alignnone size-medium wp-image-2815" title="CustomControls10" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls10-300x251.png" alt="CustomControls10 300x251 Expression Blend 4 : Control Customization" width="300" height="251" /></a></p>
<ul>
<li>Now close your document and open it again and create a rectangle and you would see that the rectangle Fill is set by Blend to default White. Even when you apply the style this white Fill is still there, this is because this fill is set on the rectangle level along with the style and hence overrides the style Fill whereas all the other properties are inherited from style.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls11.png"><img class="alignnone size-medium wp-image-2816" title="CustomControls11" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls11-300x155.png" alt="CustomControls11 300x155 Expression Blend 4 : Control Customization" width="300" height="155" /></a></p>
<ul>
<li>Now just click on the property marker next to the Fill property of the rectangle and select reset and you would be able to the Green Fill of the rectangle again.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls12.png"><img class="alignnone size-medium wp-image-2817" title="CustomControls12" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls12-300x165.png" alt="CustomControls12 300x165 Expression Blend 4 : Control Customization" width="300" height="165" /></a></p>
<ul>
<li><strong>Templates</strong>– The limitation of styles is that style can set properties on the element you are working with. This means that if you are working with a rectangle you can apply that style only on a rectangle. Whereas the template property is on the control which sets the entire Visual Tree. All of the visual states and entire stuff that makes the control.
<ul>
<li>Let’s create a button on the panel. When I right click it instead of the edit style option I have Edit template option in which I see option of Edit a copy which will create a copy of the existing default template of the Button and give us to edit and a Create Empty will create a new empty template for us to edit.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls13.png"><img class="alignnone size-medium wp-image-2818" title="CustomControls13" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls13-300x242.png" alt="CustomControls13 300x242 Expression Blend 4 : Control Customization" width="300" height="242" /></a></p>
<ul>
<li>Now when click on Edit a Copy you would see a dialog box like below asking to give a name to the <strong>style</strong>, its asking to create a style and not a template because you can only apply a style to a control and the template is a part of the style. You can also see the option of apply to all. This option will actually create the style with no name nad apply to all the button in its scope.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls14.png"><img class="alignnone size-medium wp-image-2819" title="CustomControls14" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls14-300x231.png" alt="CustomControls14 300x231 Expression Blend 4 : Control Customization" width="300" height="231" /></a></p>
<ol>
<li>We are working with the template within the style within the button. You can have a look at the xaml and see that the style has a target type set as button and the setter property template has visual states, border, grid, rectangle, etc which the complete visual tree of the button and will decide how the button looks and behaves.</li>
<li>You can see the Button Visual Tree here.</li>
</ol>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls15.png"><img class="alignnone size-medium wp-image-2820" title="CustomControls15" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls15-300x244.png" alt="CustomControls15 300x244 Expression Blend 4 : Control Customization" width="300" height="244" /></a></p>
<ul>
<li>Now just right and delete all the elements inside the grid so that we can create the visual of our button from scratch. And then press ctrl + 9 to zoom into the grid we are working on.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls16.png"><img class="alignnone size-medium wp-image-2821" title="CustomControls16" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls16-247x300.png" alt="CustomControls16 247x300 Expression Blend 4 : Control Customization" width="247" height="300" /></a></p>
<ul>
<li>Now add an ellipse and set the alignments to stretch and margins to 0</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls17.png"><img class="alignnone size-medium wp-image-2822" title="CustomControls17" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls17-300x117.png" alt="CustomControls17 300x117 Expression Blend 4 : Control Customization" width="300" height="117" /></a></p>
<ul>
<li>Now Go to the assets library and add a couple of rigs to the corners of ellipse. Also now add a textblock on the ellipse and rotate it and make the text as button. Now run the application and you would be able to the button.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls18.png"><img class="alignnone size-medium wp-image-2823" title="CustomControls18" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls18-300x105.png" alt="CustomControls18 300x105 Expression Blend 4 : Control Customization" width="300" height="105" /></a></p>
<ul>
<li>Now go over to the states and we would see how the button looks at various states like mouse over and mouse pressed, which is the same as of now as we have not added any effects. Now let’s change what the button does on mouse over and Pressed. Just select MouseOver in the states and change the color of one of the rings and then select Pressed state and change the color of the other ring. Now run the application and see if the effects work at runtime as well.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls19.png"><img class="alignnone size-medium wp-image-2824" title="CustomControls19" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls19-300x185.png" alt="CustomControls19 300x185 Expression Blend 4 : Control Customization" width="300" height="185" /></a></p>
<ul>
<li>Now let’s add some transition speed. Now select Mouse Over and change the textblock foreground to white and ellipse fill to black and also change the Default Transition speed from 0s to 3s and when we run the application we will see that all the animation states  transition very smoothly.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls20.png"><img class="alignnone size-medium wp-image-2825" title="CustomControls20" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls20-300x174.png" alt="CustomControls20 300x174 Expression Blend 4 : Control Customization" width="300" height="174" /></a></p>
<ul>
<li>Now let’s add a new transition. Click on the Arrow+ in mouse over and we could see the transitions we could use. Select the 1<sup>st</sup> option.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls21.png"><img class="alignnone size-medium wp-image-2826" title="CustomControls21" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls21-300x125.png" alt="CustomControls21 300x125 Expression Blend 4 : Control Customization" width="300" height="125" /></a></p>
<p>&nbsp;</p>
<ul>
<li>We can also set the transition effects.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls22.png"><img class="alignnone size-medium wp-image-2827" title="CustomControls22" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls22-300x198.png" alt="CustomControls22 300x198 Expression Blend 4 : Control Customization" width="300" height="198" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls23.png"><img class="alignnone size-medium wp-image-2828" title="CustomControls23" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls23-261x300.png" alt="CustomControls23 261x300 Expression Blend 4 : Control Customization" width="261" height="300" /></a></p>
<ul>
<li>Now you can add new button and apply this style we have created.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls24.png"><img class="alignnone size-medium wp-image-2829" title="CustomControls24" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls24-300x263.png" alt="CustomControls24 300x263 Expression Blend 4 : Control Customization" width="300" height="263" /></a></p>
<ul>
<li>Now if you set the background on the button it will not be applied to the button because it is taking its values from the template. Now we need to modify the template</li>
</ul>
<p>So that the value is picked up from the control. So go ahead and edit the current template and select the ellipse. Now go to the property marker of the fill and select Template Binding à Background</p>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls25.png"><img class="alignnone size-medium wp-image-2830" title="CustomControls25" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls25-300x90.png" alt="CustomControls25 300x90 Expression Blend 4 : Control Customization" width="300" height="90" /></a></p>
<ul>
<li>When we change that the value will be coming from the parent and not the template as we have template binded the control to parent. Now if we go to the Mouse Over transition we will see that background color is not changed. So we need to decide as to do we want to template bind it to parent of Control Template.</li>
<li>Let’s Template Bind the Text of the TextBlock to Button Content. So select the TextBlock in the template and goto Common Propertiesà Text and click on the PropertyMarker and select Content as button being the Content Control we need to bind to the Content of the Button. But this work fine only till our content of the button is text.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls26.png"><img class="alignnone size-medium wp-image-2831" title="CustomControls26" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls26-300x158.png" alt="CustomControls26 300x158 Expression Blend 4 : Control Customization" width="300" height="158" /></a></p>
<ul>
<li>So we have any other content then we should use content presenter for it. So add one to the template and align it to center and reset all the margins and rotate it the way you want.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls27.png"><img class="alignnone size-medium wp-image-2832" title="CustomControls27" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/CustomControls27-300x124.png" alt="CustomControls27 300x124 Expression Blend 4 : Control Customization" width="300" height="124" /></a></p>
<p>&nbsp;</p>
<p>Any Comments, feedback or suggestions are most welcome.</p>
<p>&nbsp;</p>
<div style="min-height:33px;" class="really_simple_share really_simple_share_button robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;"><iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.abhishekshukla.com%2Fexpression-suite%2Fexpression-blend%2Fexpression-blen-4-control-customization%2F&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=27&amp;locale=en_US" 
							scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe></div><div class="really_simple_share_twitter" style="width:100px;"><a target="_blank" href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Expression Blend 4 : Control Customization" data-url="http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blen-4-control-customization/" 
						data-via=""  ></a></div><div class="really_simple_share_google1" style="width:80px;"><div class="g-plusone" data-size="medium" data-href="http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blen-4-control-customization/" ></div></div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.abhishekshukla.com/expression-suite/expression-blend/expression-blen-4-control-customization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expression Blend : Resources, Scope and Resource Dictionary</title>
		<link>http://www.abhishekshukla.com/expression-suite/expression-blend/resources-in-expression-blend/</link>
		<comments>http://www.abhishekshukla.com/expression-suite/expression-blend/resources-in-expression-blend/#comments</comments>
		<pubDate>Mon, 21 May 2012 07:21:54 +0000</pubDate>
		<dc:creator>Abhishek</dc:creator>
				<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Expresion Blend]]></category>
		<category><![CDATA[Resources]]></category>

		<guid isPermaLink="false">http://www.abhishekshukla.com/?p=2730</guid>
		<description><![CDATA[&#160; Resources in Expression Blend We will be using Microsoft Expression Blend 4 for this tutorial. Resources are integral part of WPF and Silverlight. A resource in nothing but a name and value pair. Say for ex  - If I talk to a 2nd grade student and say my phone’s color is #FF000000, he would [...]]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/37-1024x492.png" width="240" title="Expression Blend : Resources, Scope and Resource Dictionary" alt="37 1024x492 Expression Blend : Resources, Scope and Resource Dictionary" />
		</p><p>&nbsp;</p>
<h1>Resources in Expression Blend</h1>
<p>We will be using Microsoft Expression Blend 4 for this tutorial.</p>
<p>Resources are integral part of WPF and Silverlight. A resource in nothing but a name and value pair. Say for ex  - If I talk to a 2<sup>nd</sup> grade student and say my phone’s color is #FF000000, he would not understand what’s that that but when I say my phone’s color is black, he might or might not know what I am talking about.</p>
<p>This is the concept used by Microsoft behind using resources. This enables us to think in terms of names and labels as opposed to talking about the values. Let see this working in Expression Blend.</p>
<ul>
<li>Create a new project in Expression Blend and name in Resources.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/1.png"><img class="alignnone size-medium wp-image-2731" title="1" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/1-300x259.png" alt="1 300x259 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="259" /></a></p>
<ul>
<li>Create a rectangle on to the design surface.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/2.png"><img class="alignnone size-medium wp-image-2732" title="2" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/2-300x162.png" alt="2 300x162 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="162" /></a></p>
<p>&nbsp;</p>
<ul>
<li>Go to the properties tab and select the color green. Now when you work for any clients or customer designing applications for them they would have specification of color coding standards they want you to follow. Resources follow the same trend so that you can name your resource and use it at multiple places by just referring its name. We will see how that happens a little later.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/3.png"><img class="alignnone size-medium wp-image-2733" title="3" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/3-300x162.png" alt="3 300x162 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="162" /></a></p>
<p> Click on the PropertyMarker as shown in the Image and select ConvertToNewResource. Every property in Blend has a property marker that means we can convert all the property in blend into a resource.   </p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/4.png"><img class="alignnone size-medium wp-image-2734" title="4" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/4-300x150.png" alt="4 300x150 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="150" /></a></p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/5.png"><img class="alignnone size-medium wp-image-2735" title="5" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/5-300x145.png" alt="5 300x145 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="145" /></a></p>
<ul>
<li>Just name the property as MyGreen and click ok.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/6.png"><img class="alignnone size-medium wp-image-2736" title="6" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/6-300x187.png" alt="6 300x187 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="187" /></a></p>
<ul>
<li>Now as would notice a couple of things have changed. Instead of the ColorPicker now we see Color resources and the also the list of resources available. Also as you can see the MyGreen is highlighted It is the Color that I am using currently.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/7.png"><img class="alignnone size-medium wp-image-2737" title="7" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/7-300x160.png" alt="7 300x160 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="160" /></a></p>
<p>&nbsp;</p>
<ul>
<li>Now just create a Ellipse and by default you would see that the color selected is the MyGreen color as Blend figures out that MyGreen is the color I am working and probably that’s the color I need.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/8.png"><img class="alignnone size-medium wp-image-2738" title="8" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/8-300x148.png" alt="8 300x148 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="148" /></a></p>
<p>&nbsp;</p>
<ul>
<li>Now Select the Fill as Gradient Brush</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/9.png"><img class="alignnone size-medium wp-image-2739" title="9" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/9-300x137.png" alt="9 300x137 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="137" /></a></p>
<p>&nbsp;</p>
<ul>
<li>Now go to the Property Marker for the Gradient Brush and Go To local resource and select MyGreen. As you see are using MyGreen as both a SolidColor and a Gradient Color. The Color is the same but we are using it at different places.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/10.png"><img class="alignnone size-medium wp-image-2740" title="10" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/10-300x141.png" alt="10 300x141 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="141" /></a></p>
<p>&nbsp;</p>
<ul>
<li>Now go to the resources tab at the top and expand that user control and you would see that the MyGreen resource is available in the UserControl Scope.</li>
</ul>
<p>&nbsp;</p>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/11.png"><img class="alignnone size-medium wp-image-2741" title="11" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/11-300x181.png" alt="11 300x181 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="181" /></a></p>
<ul>
<li>Now if we change the color here we are able to change the color at all the controls using this resource. So using resource you don’t have to go to each and every control and change the color.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/12.png"><img class="alignnone size-medium wp-image-2742" title="12" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/12-300x156.png" alt="12 300x156 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="156" /></a></p>
<ul>
<li>Now go back to selection tool and select the Ellipse. Now go to the Fill property marker of the Ellipse and select ConvertToNewResource.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/13.png"><img class="alignnone size-medium wp-image-2743" title="13" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/13-300x180.png" alt="13 300x180 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="180" /></a></p>
<ul>
<li>Name it as BlackToMyGreen.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/14.png"><img class="alignnone size-medium wp-image-2744" title="14" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/14-300x245.png" alt="14 300x245 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="245" /></a></p>
<ul>
<li>Now we see a Local Brush resource is available. You should know that a color is just is a 24bit value that probably represents some transparent color in the spectrum but a brush can be a single color or a set color or something else.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/15.png"><img class="alignnone size-medium wp-image-2745" title="15" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/15-300x155.png" alt="15 300x155 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="155" /></a></p>
<p>&nbsp;</p>
<ul>
<li>Now let’s go back to the Resources tab and expand the UserControl again and change the MyGreen to some other value. Now you would see that not only MyGreen has changed but also the BlackToMyGreen has also changed, so this implies that resources can use other resources as well.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/16.png"><img class="alignnone size-medium wp-image-2746" title="16" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/16-300x146.png" alt="16 300x146 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="146" /></a>              </p>
<p><strong> </strong></p>
<h1>Scope of Resources in Expression Blend</h1>
<p>Now let’s talk about <strong>Scope</strong> of resources. Scope of a resource simply means where are we going to look when we are getting a concept. Let’s talk about a 2<sup>nd</sup> grader to whom we say my phone is black. Now he might know what is black, if that’s the case he is going immediately know what color you are talking about. Let’s say he doesn’t know what is black so he’s going ask his parents. Maybe his parents are able to answer it or they then go to their parents and ask what does black mean? This is exactly what scope means. You can define a concept at any level &#8211; object level, on a parent, on a document, in an application or a resource dictionary. Now when we say MyGreen then Silverlight or WPF will be able to figure out what is MyGreen. </p>
<p>Let’s see this with the help of an example: </p>
<ul>
<li>Delete the rectangle and grid in the application we are working on and draw 2 identical Grids as shown below:</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/17.png"><img class="alignnone size-medium wp-image-2750" title="17" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/17-300x149.png" alt="17 300x149 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="149" /></a></p>
<ul>
<li>Now select the left grid and go to its properties. And select the background as Green.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/18.png"><img class="alignnone size-medium wp-image-2751" title="18" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/18-300x163.png" alt="18 300x163 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="163" /></a></p>
<ul>
<li>You can click on the shortcut key and convert a color to resource.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/19.png"><img class="alignnone size-medium wp-image-2752" title="19" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/19-300x147.png" alt="19 300x147 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="147" /></a></p>
<ul>
<li>And we will name it Grass and we will define it in the grid instead of the usercontrol. </li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/20.png"><img class="alignnone size-medium wp-image-2753" title="20" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/20-300x220.png" alt="20 300x220 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="220" /></a> </p>
<ul>
<li>Now give a background to the other grid and create a new color resource in that grid named as Grass.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/21.png"><img class="alignnone size-medium wp-image-2754" title="21" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/21-300x155.png" alt="21 300x155 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="155" /></a></p>
<ul>
<li>Clear the brush on both the grids using the shortcut below: </li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/22.png"><img class="alignnone size-medium wp-image-2755" title="22" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/22-300x152.png" alt="22 300x152 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="152" /></a></p>
<ul>
<li>Create a rectangle in one of the two grids. And using the color resources make the Fill of the rectangle as Grass. </li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/23.png"><img class="alignnone size-medium wp-image-2756" title="23" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/23-300x147.png" alt="23 300x147 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="147" /></a></p>
<ul>
<li>Now using the selection tool drop the rectangle from one grid to another by keeping the alt key pressed. </li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/24.png"><img class="alignnone size-medium wp-image-2757" title="24" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/24-300x221.png" alt="24 300x221 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="221" /></a></p>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/25.png"><img class="alignnone size-medium wp-image-2758" title="25" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/25-300x258.png" alt="25 300x258 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="258" /></a> </p>
<ul>
<li>What you see now is that the rectangle is using the local Resource Grass. Whenever an element is trying to figure out the meaning of the defined resources, it first looks into its own defined resources, then its parent resources and if it still is not able to find it will look further up till the root of the UserControl. And if still it is not able to find it there it will look for it in the application resources. But if a resource is defined at multiple levels then the closest one is adopted by the element. i.e. the resource is defined at a parent level as well as the application level then one the parent returns the meaning of the resource then the element stops looking and uses the same.</li>
</ul>
<p>&nbsp;</p>
<ul>
<li>Let’s take another rectangle and drop it on the panel and this rectangle also uses the Fill as Grass but is not able to find it. That’s because the Rectangle does not know what Grass is, it asks LayoutRoot but LayoutRoot also does not know what Grass is, then it asks the UserControl which still does not know what grass is. So the unresolved resource gives us a blank fill.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/26.png"><img class="alignnone size-medium wp-image-2759" title="26" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/26-300x187.png" alt="26 300x187 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="187" /></a></p>
<ul>
<li>Let’s go ahead and give it a SolidColorBrush and set the alpha value of it to 100 as whenever we get an unresolved resource blend gives it a transparent white brush. </li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/27.png"><img class="alignnone size-medium wp-image-2760" title="27" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/27-300x130.png" alt="27 300x130 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="130" /></a> </p>
<ul>
<li>Now convert this to resource and select it to save at the application level.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/28.png"><img class="alignnone size-medium wp-image-2761" title="28" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/28-300x130.png" alt="28 300x130 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="130" /></a></p>
<ul>
<li>Let’s go the resources tab and we see that Grass is defined as different color for different levels.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/29.png"><img class="alignnone size-medium wp-image-2762" title="29" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/29-300x176.png" alt="29 300x176 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="176" /></a></p>
<p><strong> </strong></p>
<h1>Resource Dictionary in Expression Blend</h1>
<p>&nbsp;</p>
<p>Let’s again talk about our 2<sup>nd</sup> grader who went to his parents to ask what is black, who in turn ask their parent as to what is black. Say their parent also does not know what is black so what they would do is grab one of the reference guides or resource dictionary and look for black color, if that resource dictionary does not have an answer for blue then they will check in other available resource dictionaries. In this case a Resource Dictionary is a single xaml file that contains key value pairs in it.</p>
<p>Let’s have a look at this with the help of an example:</p>
<ul>
<li>Create a new solution in Blend named ResourceDictionaries and create a rectangle in it.</li>
</ul>
<p><a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/30.png"><img class="alignnone size-medium wp-image-2765" title="30" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/30-300x126.png" alt="30 300x126 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="126" /></a></p>
<ul>
<li>Convert that into a resource. But we will define it in a new ResourceDictionary.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/31.png"><img class="alignnone size-medium wp-image-2766" title="31" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/31-300x152.png" alt="31 300x152 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="152" /></a></p>
<ul>
<li>As Soon as we do that a new xaml is added to the project. The reason for giving description of MyGreen here instead of the application level is the same as printing all the information in the book in the 2<sup>nd</sup> grader example. We can very easily transfer this dictionary to a different application.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/32.png"><img class="alignnone size-medium wp-image-2767" title="32" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/32-300x125.png" alt="32 300x125 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="125" /></a></p>
<ul>
<li>Let’s just create a couple of more dictionaries. Right click the project and select Add new item and select Resource Dictionary and click ok.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/33.png"><img class="alignnone size-medium wp-image-2768" title="33" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/33-300x179.png" alt="33 300x179 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="179" /></a></p>
<ul>
<li>Now we go the rectangle and change the fill color and save it into the resource dictionary 2. Change the color again and save it to the resource dictionary 3.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/34.png"><img class="alignnone size-medium wp-image-2769" title="34" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/34-300x156.png" alt="34 300x156 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="156" /></a></p>
<ul>
<li>Now Delete the rectangle and just drag and drop a new one. What you will see is that this rectangle’s fill is yellow i.e. the color from the last resource dictionary. This happens because Blend creates a merged dictionary. So when a resource is found in a resource dictionary the element will look for any other occurrences of the same resource in all the resource dictionaries and will override the previous values with the new one. Below is how the resource dictionaries look like.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/35.png"><img class="alignnone size-medium wp-image-2770" title="35" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/35-300x139.png" alt="35 300x139 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="139" /></a></p>
<ul>
<li>We can add or remove reference to a resource dictionary using the interface below.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/36.png"><img class="alignnone size-medium wp-image-2771" title="36" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/36-300x149.png" alt="36 300x149 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="149" /></a></p>
<ul>
<li>And when we do the colors will follow a fallback mechanism.</li>
</ul>
<p> <a href="http://www.abhishekshukla.com/wp-content/uploads/2012/05/37.png"><img class="alignnone size-medium wp-image-2772" title="37" src="http://www.abhishekshukla.com/wp-content/uploads/2012/05/37-300x144.png" alt="37 300x144 Expression Blend : Resources, Scope and Resource Dictionary" width="300" height="144" /></a></p>
<p>I would like to state here that as of now i.e. Silverlight 4 all the resources are static resource and will take the value at the time instantiation. Where as in WPF we do have Dynamic Resources and at runtime everything will update.</p>
<p>Please find the source sode for the soultions at location below:</p>
<p><a target="_blank" href="http://i.minus.com/1337680217/iM-3YUH7dLJB6ELGpiplpQ/dbuofcNvmgf7Uz.zip">http://i.minus.com/1337680217/iM-3YUH7dLJB6ELGpiplpQ/dbuofcNvmgf7Uz.zip</a></p>
<p><a target="_blank" href="http://i.minus.com/1337680215/Uq65IIajg7rV01b2c715dQ/dbvtJW3hnSasrW.zip">http://i.minus.com/1337680215/Uq65IIajg7rV01b2c715dQ/dbvtJW3hnSasrW.zip</a> </p>
<p>Any comments, feedbacks or question are most welcome.</p>
<div style="min-height:33px;" class="really_simple_share really_simple_share_button robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;"><iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.abhishekshukla.com%2Fexpression-suite%2Fexpression-blend%2Fresources-in-expression-blend%2F&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=27&amp;locale=en_US" 
							scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe></div><div class="really_simple_share_twitter" style="width:100px;"><a target="_blank" href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Expression Blend : Resources, Scope and Resource Dictionary" data-url="http://www.abhishekshukla.com/expression-suite/expression-blend/resources-in-expression-blend/" 
						data-via=""  ></a></div><div class="really_simple_share_google1" style="width:80px;"><div class="g-plusone" data-size="medium" data-href="http://www.abhishekshukla.com/expression-suite/expression-blend/resources-in-expression-blend/" ></div></div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.abhishekshukla.com/expression-suite/expression-blend/resources-in-expression-blend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
