Click here to Skip to main content
15,867,327 members
Articles / Desktop Programming / WPF
Tip/Trick

ObservableDictionary!

Rate me:
Please Sign up or sign in to vote.
4.95/5 (7 votes)
22 May 2010CPOL1 min read 45.3K   4   6
In WPF/Silverlight, you might want to bind to a dictionary. Here's a couple of websites I found.
I was writing some code today, and decided it would be real nice if I could use an ObservableDictionary to allow the possible binding of items to a WPF/Silverlight control. Of course, I was dismayed to find that Microsoft (once again) failed to anticipate the needs of (quite possibly) the laziest programmer ever to stop around in Visual Studio - there was no such collection in .Net. Lookout google, here I come.

I was pleased my search was a relatively short one, and in the interest of saving you the time of conducting an identical search, I present you with my results - a sort of one-stop shopping experience, if you will.

The first link provides the article discussing the basic ObservableDictionary:

http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/[^]

And the second link allows you to add XML serialization:

http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx[^]

As with anything on the internet, I don't know how long these things will be around, so if I were you, I'd scoop the code as soon as humanly possible. I'[m working on an article that actually uses some of this code, so eventually, you'll be able to get it here as well (I'll get the original authors' permissions before I do that, though).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions

 
GeneralI just posted an alternative as part of the solution to anot... Pin
John Stewien8-Jun-11 12:51
John Stewien8-Jun-11 12:51 
I just posted an alternative as part of the solution to another problem here http://www.codeproject.com/KB/cs/ConcurrentCollections.aspx
My aim was to make my ObservableDictionary a bit more readable that the one put up by Dr WPF.
GeneralAwesome. I googled ObservableDictionary and the Dr. WPF link... Pin
SledgeHammer0122-May-10 13:32
SledgeHammer0122-May-10 13:32 
GeneralYou might want to check out the Reactive Extensions for .Net... Pin
Matthew Dennis22-May-10 13:30
sysadminMatthew Dennis22-May-10 13:30 
GeneralReason for my vote of "5". To offset the univoting schmuck. Pin
Wes Aday22-May-10 13:12
professionalWes Aday22-May-10 13:12 
GeneralI beg to differ. I needed an observable dictionary, and I am... Pin
#realJSOP22-May-10 8:43
mve#realJSOP22-May-10 8:43 
GeneralReason for my vote of 1 links are not tips Pin
SledgeHammer0122-May-10 8:04
SledgeHammer0122-May-10 8:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.