<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Can I bind my ItemsControl to a dictionary?</title>
	<atom:link href="http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/feed/" rel="self" type="application/rss+xml" />
	<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/</link>
	<description>Drinking (and serving) the WPF Kool-Aid since 2002</description>
	<lastBuildDate>Mon, 30 Aug 2010 18:54:01 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Brian</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2979</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Thu, 26 Aug 2010 19:38:55 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2979</guid>
		<description>This solved exactly the problem I was having! Thanks for writing it.

I did have a bit of trouble for bit there as I had bound my source to Dictionary.Values, but after reading through the comments I was able to bind the source directly to the Dictionary as suggested and then change my data context to &#039;Value&#039; in the XAML and it worked like a charm.

One stumbling block I ran in to was that the ObservableSortedDictionary constructor requires an explicit IComparer object whereas the base SortedDictionary does not. Your observable version would have been a lot easier to drop in if it also used a default comparer when none is supplied.

Cheers,
Brian</description>
		<content:encoded><![CDATA[<p>This solved exactly the problem I was having! Thanks for writing it.</p>
<p>I did have a bit of trouble for bit there as I had bound my source to Dictionary.Values, but after reading through the comments I was able to bind the source directly to the Dictionary as suggested and then change my data context to &#8216;Value&#8217; in the XAML and it worked like a charm.</p>
<p>One stumbling block I ran in to was that the ObservableSortedDictionary constructor requires an explicit IComparer object whereas the base SortedDictionary does not. Your observable version would have been a lot easier to drop in if it also used a default comparer when none is supplied.</p>
<p>Cheers,<br />
Brian</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fan</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2978</link>
		<dc:creator>Fan</dc:creator>
		<pubDate>Thu, 26 Aug 2010 04:30:56 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2978</guid>
		<description>another line should be added to Deserialization constructor or the TrueDictionary will not be updated when deserializing:

_dictionaryCacheVersion = -1;</description>
		<content:encoded><![CDATA[<p>another line should be added to Deserialization constructor or the TrueDictionary will not be updated when deserializing:</p>
<p>_dictionaryCacheVersion = -1;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fan</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2977</link>
		<dc:creator>Fan</dc:creator>
		<pubDate>Thu, 26 Aug 2010 03:44:05 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2977</guid>
		<description>I think the _keyedEntryCollection assignment is missing for the Deserialization constructor that causes the deserializating failure.</description>
		<content:encoded><![CDATA[<p>I think the _keyedEntryCollection assignment is missing for the Deserialization constructor that causes the deserializating failure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2970</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Tue, 03 Aug 2010 16:22:02 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2970</guid>
		<description>Ok, well I&#039;ve programatically set the Binding on the control&#039;s Load event by building the path string based on other bound properties.

Something like:

private void Control_Loaded(object sender, RoutedEventArgs e)
{
        // MyDataItem would contain a reference to a data source and key
        // the tag is assigned to be MyDataItem created using a IMultiConverter defined in the xaml 

        MyDataItem dataItem = ((sender as FrameworkElement).Tag as MyDataItem);

        Binding b = new Binding(&quot;[&quot;+dataItem.Key+&quot;]&quot;);
        b.Source = dataItem.DataSourceWithIndexer;

        if (sender is TextBox)
        {
                (sender as TextBox).SetBinding(TextBox.TextProperty, b);
        }
}

This works, but was hoping to do this within the XAML. 

Also, is it correct to set Binding in the Load event?

Thanks again
Sam</description>
		<content:encoded><![CDATA[<p>Ok, well I&#8217;ve programatically set the Binding on the control&#8217;s Load event by building the path string based on other bound properties.</p>
<p>Something like:</p>
<p>private void Control_Loaded(object sender, RoutedEventArgs e)<br />
{<br />
        // MyDataItem would contain a reference to a data source and key<br />
        // the tag is assigned to be MyDataItem created using a IMultiConverter defined in the xaml </p>
<p>        MyDataItem dataItem = ((sender as FrameworkElement).Tag as MyDataItem);</p>
<p>        Binding b = new Binding(&#8221;["+dataItem.Key+"]&#8220;);<br />
        b.Source = dataItem.DataSourceWithIndexer;</p>
<p>        if (sender is TextBox)<br />
        {<br />
                (sender as TextBox).SetBinding(TextBox.TextProperty, b);<br />
        }<br />
}</p>
<p>This works, but was hoping to do this within the XAML. </p>
<p>Also, is it correct to set Binding in the Load event?</p>
<p>Thanks again<br />
Sam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2969</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Tue, 03 Aug 2010 15:35:09 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2969</guid>
		<description>apologies, submission removed content of &#039;[]&#039;, should read:

e.g. Path=&#039;.[{Binding indexerKey}]&#039;

Thanks,
Sam</description>
		<content:encoded><![CDATA[<p>apologies, submission removed content of &#8216;[]&#8216;, should read:</p>
<p>e.g. Path=&#8217;.[{Binding indexerKey}]&#8216;</p>
<p>Thanks,<br />
Sam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2968</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Tue, 03 Aug 2010 15:33:43 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2968</guid>
		<description>Hi Dr WPF/All,

Does anybody know or can tell me a way of binding to a dictionary using a dynamic key.

e.g. Path = &quot;.[]&quot;

I&#039;ve used your (Dr WPF) ObjectReference class in combination with the controls tag property to hold the key info, I&#039;ve also tried MultiBinding.

The problem i have is converting back, unless the path can be set dynamically (which is difficult not being a dp) I have to update the data source (indexer) from within the converter which is obviously wrong and bypasses validation.

Has anyone got any ideas?

TIA
Sam</description>
		<content:encoded><![CDATA[<p>Hi Dr WPF/All,</p>
<p>Does anybody know or can tell me a way of binding to a dictionary using a dynamic key.</p>
<p>e.g. Path = &#8220;.[]&#8221;</p>
<p>I&#8217;ve used your (Dr WPF) ObjectReference class in combination with the controls tag property to hold the key info, I&#8217;ve also tried MultiBinding.</p>
<p>The problem i have is converting back, unless the path can be set dynamically (which is difficult not being a dp) I have to update the data source (indexer) from within the converter which is obviously wrong and bypasses validation.</p>
<p>Has anyone got any ideas?</p>
<p>TIA<br />
Sam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Grant</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2923</link>
		<dc:creator>Grant</dc:creator>
		<pubDate>Sat, 29 May 2010 03:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2923</guid>
		<description>I started out looking for an observable dictionary, and now i wonder if its even appropriate.  What is a dictionary really?  It&#039;s an index to a collection of items.  There are many ways to find an item in a collection.  Before using an observable dictionary, consider if a hash table index is even really needed.  It may be over kill to index a screen of items, and we are just talking about WPF here.   More than likely a linear iteration will be all the speed you need for finding a visible item.  

At the very least, first use a linear search.  If ya really need to search faster, then go for a dictionary or some other indexing system. 

Another approach is to really just keep things in a dictonary, and only fill your UX with &quot;pages&quot; of items form the dictionary.  That&#039;s the whole point of some of the virtualized controls.  

My two cents, I hope it helps someone think about the problem differently.</description>
		<content:encoded><![CDATA[<p>I started out looking for an observable dictionary, and now i wonder if its even appropriate.  What is a dictionary really?  It&#8217;s an index to a collection of items.  There are many ways to find an item in a collection.  Before using an observable dictionary, consider if a hash table index is even really needed.  It may be over kill to index a screen of items, and we are just talking about WPF here.   More than likely a linear iteration will be all the speed you need for finding a visible item.  </p>
<p>At the very least, first use a linear search.  If ya really need to search faster, then go for a dictionary or some other indexing system. </p>
<p>Another approach is to really just keep things in a dictonary, and only fill your UX with &#8220;pages&#8221; of items form the dictionary.  That&#8217;s the whole point of some of the virtualized controls.  </p>
<p>My two cents, I hope it helps someone think about the problem differently.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andreja</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-2881</link>
		<dc:creator>andreja</dc:creator>
		<pubDate>Thu, 20 May 2010 11:44:36 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-2881</guid>
		<description>add this if you want your solution to serialize to xml

http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx</description>
		<content:encoded><![CDATA[<p>add this if you want your solution to serialize to xml</p>
<p><a href="http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx" rel="nofollow">http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr. WPF</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-765</link>
		<dc:creator>Dr. WPF</dc:creator>
		<pubDate>Wed, 07 Apr 2010 18:28:19 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-765</guid>
		<description>Excellent, Rocky!  Glad to hear it works in SL... I&#039;ve been meaning to port it and test it, but you saved me the time.  :D</description>
		<content:encoded><![CDATA[<p>Excellent, Rocky!  Glad to hear it works in SL&#8230; I&#8217;ve been meaning to port it and test it, but you saved me the time.  <img src='http://drwpf.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rocky Smith</title>
		<link>http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/comment-page-2/#comment-764</link>
		<dc:creator>Rocky Smith</dc:creator>
		<pubDate>Wed, 07 Apr 2010 18:25:31 +0000</pubDate>
		<guid isPermaLink="false">http://drwpf.com/blog/?p=8#comment-764</guid>
		<description>Hot damn! I rarely use 3rd party code because I always seem to run into issues. I just removed some of the serializable stuff (I’m using Silverlight 3) and it worked perfectly. Big thanks for takin’ the time to do this!</description>
		<content:encoded><![CDATA[<p>Hot damn! I rarely use 3rd party code because I always seem to run into issues. I just removed some of the serializable stuff (I’m using Silverlight 3) and it worked perfectly. Big thanks for takin’ the time to do this!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
