<?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>Simon&#039;s Wonder World &#187; item</title>
	<atom:link href="http://blog.simonstahl.com/tag/item/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.simonstahl.com</link>
	<description>Just another European geek in Silicon Valley</description>
	<lastBuildDate>Tue, 19 Apr 2011 22:01:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Define some items in a ListBox as unselectable</title>
		<link>http://blog.simonstahl.com/2010/01/11/define-some-items-in-a-listbox-as-unselectable/</link>
		<comments>http://blog.simonstahl.com/2010/01/11/define-some-items-in-a-listbox-as-unselectable/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 23:48:47 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[XAML]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[item]]></category>
		<category><![CDATA[listbox]]></category>
		<category><![CDATA[listboxitem]]></category>
		<category><![CDATA[unselectable]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=51</guid>
		<description><![CDATA[It seems to be a quite common problem that one does not know how to set one or more items in a ListBox to unselectable or disabled. The same principle as described here can also be user for similar problems like setting a different background color for some items. First we&#8217;re going to create a [...]]]></description>
			<content:encoded><![CDATA[<p>It seems to be a quite common problem that one does not know how to set one or more items in a <strong>ListBox </strong>to <strong>unselectable</strong> or <strong>disabled</strong>.</p>
<p>The same principle as described here can also be user for similar problems like setting a different background color for some items.</p>
<p>First we&#8217;re going to create a simple domain class with a property that describes if the item should be selectable or not.</p>
<pre class="brush:c#">public class MyDataObject {
    public string Name { get; set; }
    public bool IsSelectable { get; set; }
}</pre>
<p><span id="more-51"></span>Next we create a <strong>XAML</strong> Window that contains a ListBox. In this ListBox we define a custom <strong>ItemContainerStyle </strong>with a Style that defines if the Item will be selected or not. And finally we bind this Style to the <strong>IsSelectable </strong>property from our data object.</p>
<pre class="brush:xml">

            <!--
                <Setter Property="Focusable" Value="{Binding IsSelectable}" />

--></pre>
<p>And now we just have to fill the <strong>ItemsSource</strong> from the ListBox and we can run the example.</p>
<pre class="brush:c#">public partial class MainWindow : Window {
    public MainWindow() {
        InitializeComponent();

        myListBox.ItemsSource =
            from i in Enumerable.Range(0, 10)
            select new MyDataObject() { Name = string.Format("Object {0}", i), IsSelectable = i % 3 != 0 };
    }
}</pre>
<p>That&#8217;s all. Easy, isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2010/01/11/define-some-items-in-a-listbox-as-unselectable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

