Home / dating bogs / Wpf treeview binding not updating

Wpf treeview binding not updating

Many moons ago, I asked on the WPF forums if anybody had a way of data-binding the Selected Items property of a List Box.Standard data binding doesn’t work, because the Selected Items property is read-only, and understandably so: how would you like it if I injected an arbitrary collection into your List Box and expected you to keep it up to date as the selection changed?As no one gave me an answer, I was forced to use my gray-matter and invent a solution of my own.Since a similar question came up again recently on Stack Overflow, I thought I’d share what I came up with.

I won’t bore you with the code – see the download link below.

The XAML looks like this: using a data binding to my Selected Names property.

With that in place the Selected Names collection in my View Model is updated whenever Selected Items on the List Box changes.

And to prove it works the other way to, I’ve created a Select All command on the View Model that puts all available names into the Selected Names collection.

When you press the button you’ll see that the List Box obediently updates to show all items selected.


  1. Jul 12, 2014. WinRT and Silverlight before it still plays catchup to all the WPF features although WinRT has some nice features not present in the current version of WPF – there's even a “user voice” asking to bring some of WPF's features to WinRT, such as multi bindings, binding in style setters, data typed templates.

  2. May 5, 2007. This blog entry demonstrates the fundamentals of binding a WPF TreeView to a DataSet with two related DataTables. The technique presented herein could easily be extended to fit more sophisticated requirements, such as binding to more than two tables. Many applications need to display hierarchical.

  3. Jan 28, 2010. Show“Cannot rename directory”, ex. Message;. } } } } // Tell WPF the name has changed. Note if the same control. // is being used to display vs. edit then the. // binding will need to force WPF3x to re-read the property value. // This is done by using a RefreshValueConverter;. // under. NET4 this won't be.

  4. Aug 29, 2011. WPF is really awesome to build reactive applications and data binding is here to push useful information inside of the User Interface. All is done. Now, I wan't to talk about something which can useful in every WPF application how to wait for the rendering UI to be done. No apparent freeze of the UI.

  5. May 27, 2011. I decide to show my data in the UI inside a WPF Treeview and some general list of items with no specific structure. When the user. One additional change you might notice is the introduction of the INotifyPropertyChanged interface which will help me to update the UI elements using binding. Now all that.

Leave a Reply

Your email address will not be published. Required fields are marked *