WPF ListBox Rebind

WPF ListBox Rebind

Old forum URL: forums.lhotka.net/forums/t/9712.aspx


rmroch posted on Thursday, November 04, 2010

Hello,

I am working on a WPF application using CSLA version 3.6.0.0.  We do plan to upgrade to the current version of CSLA in the future but need to schedule time for regression testing.  I have a window with a ListBox control that is bound to an empty BusinessList object.  I have a button which opens a window where the user can enter some data to create a Business object and save it then the child window calls back to the parent window and adds that new Business object to the ((businessObjectCollection)ListBox.DataContext).Add(businessObject).  But the ListBox does not get refreshed with the newly added object.  I saw a post that CSLA uses a style of interface but not the Observable interface which is why the ListBox does not update itself.  What should I look at to fix this?

RockfordLhotka replied on Thursday, November 04, 2010

There is no easy fix, that's the problem. Microsoft really put us in a bad place.

WPF uses ObservableCollection<T>. Windows Forms uses BindingList<T>. The two are basically incompatible, though WPF sort of works with BindingList<T>.

CSLA 3.x uses BindingList<T>. CSLA 4 defaults to ObservableCollection<T>, and has secondary list classes using BindingList<T> for Windows Forms work.

You can search the internet for ways to bind WPF to a BindingList<T>. There are some solutions out there, but none are elegant or easy. That might be your only option though, at least until you can get to CSLA 4/.NET 4.

Copyright (c) Marimer LLC