<?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>Veracity Solutions Blog &#187; RelativeSource</title>
	<atom:link href="http://blogs.veracitysolutions.com/tag/relativesource/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.veracitysolutions.com</link>
	<description>Software Consulting That Rocks</description>
	<lastBuildDate>Thu, 22 Apr 2010 17:21:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To Create A ListBox with CheckBoxes (or RadioButtons) In Silverlight 3</title>
		<link>http://blogs.veracitysolutions.com/how-to-create-a-listbox-with-checkboxes-or-radiobuttons-in-silverlight-3/</link>
		<comments>http://blogs.veracitysolutions.com/how-to-create-a-listbox-with-checkboxes-or-radiobuttons-in-silverlight-3/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 16:38:10 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[CheckBox]]></category>
		<category><![CDATA[ListBox]]></category>
		<category><![CDATA[RadioButton]]></category>
		<category><![CDATA[RelativeSource]]></category>
		<category><![CDATA[Silverlight 3]]></category>

		<guid isPermaLink="false">http://blogs.veracitysolutions.com/?p=612</guid>
		<description><![CDATA[To set the scene: You have a ListBox that is being populated by some collection and you want the user to scroll through the ListBox and either check a bunch of things or check one thing. Basically, you want a list of checkable items. If this is what you’re trying to do, this is the [...]]]></description>
			<content:encoded><![CDATA[<p>To set the scene: You have a ListBox that is being populated by some collection and you want the user to scroll through the ListBox and either check a bunch of things or check one thing. Basically, you want a list of checkable items. If this is what you’re trying to do, this is the tutorial that lets you do it without any code… simply by applying a style to your ListBox. </p>
<p>Download finished tutorial: <a href='http://www.designersilverlight.com/wp-content/uploads/2009/08/ListBoxCheckBoxTutorial.zip'>ListBox With CheckBoxes (or RadioButtons) Project in Silverlight 3 </a>
 </p>
<p><a href="http://designersilverlight.com/SilverlightSamples/ListBoxCheckBox/">Go here to see the final result</a>.</p>
<p>First, you should know right off the bat that this tutorial is for <strong>Silverlight 3 only</strong>. It uses a data binding functionality called RelativeSource binding that isn’t available in earlier versions of Silverlight.</p>
<p>OK… to start out, right click on your ListBox and go to:</p>
<p>Edit Additional Templates –&gt; Edit Generated Item Container (ItemContainerStyle) –&gt; Edit a Copy…</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/08/clip_image001.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2009/08/clip_image001_thumb.png" width="602" height="90" /></a></p>
<p>Name your new template and Blend will generate the default ItemContainerStyle for the ListBox.</p>
<p>Split up the grid so that there is room for your CheckBox or RadioButton. I’m going to put mine on the left, set HorizonalAlignment and VerticalAlignment to “Center”, reset the Content property&quot; and make the whole thing twice as big by setting the RenderTransform X and Y to 2.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/08/clip_image0015.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="clip_image001[5]" src="http://www.designersilverlight.com/wp-content/uploads/2009/08/clip_image0015_thumb.png" width="278" height="123" /></a></p>
<p>If you’re really picky about making sure that your CheckBox is centered appropriately, change the Width and Height to “16”.</p>
<p>OK… so we’ve got the CheckBox in there, but it doesn’t really do anything. So let’s set the binding so that it works. Sadly, Blend doesn’t have an obvious way (that I can see) of setting a RelativeSource binding, so just type this into your CheckBox (or RadioButton):</p>
<pre><span style="color: red">IsChecked</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding </span><span style="color: red">RelativeSource</span><span style="color: blue">={</span><span style="color: #a31515">RelativeSource </span><span style="color: red">TemplatedParent</span><span style="color: blue">}, </span><span style="color: red">Path</span><span style="color: blue">=IsSelected, </span><span style="color: red">Mode</span><span style="color: blue">=TwoWay}&quot;</span></pre>
<p> This binding will make it so that when the user selects or unselects an item, the CheckBox or RadioButton will reflect this decision. Similarly, when the user checks or unchecks the CheckBoxes or RadioButtons, the selection will reflect these actions.</p>
<p>Now, we just need to make sure our selection option on the ListBox reflects our interface choice. If you’re using CheckBoxes, make sure that your ListBox SelectionMode is set to “Multiple” or “Extended”. </p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/08/clip_image0011.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="clip_image001[1]" src="http://www.designersilverlight.com/wp-content/uploads/2009/08/clip_image0011_thumb.png" width="251" height="93" /></a></p>
<p>If you’re using RadioButtons, it needs to be set to “Single”.</p>
<p>And you’re done! You can now set any ListBox to hold a list of checkable items simply by assigning it this ItemContainerStyle.</p>
<p><img src="http://www.designersilverlight.com/wp-content/uploads/2009/09/CheckBoxRadioButtonExample.png" alt="CheckBoxRadioButtonExample" title="CheckBoxRadioButtonExample" width="667" height="277" class="alignnone size-full wp-image-846" /></p>
<p>And you should have something that <a href="http://designersilverlight.com/SilverlightSamples/ListBoxCheckBox/">looks and acts like this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/how-to-create-a-listbox-with-checkboxes-or-radiobuttons-in-silverlight-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
