Binding Between VM Prop and Model Prop Getting Broken

Topics: Issues / bugs
Jul 19, 2012 at 7:05 PM

This is a bit complicated, so bear with me...

I have a window that contains a ReorderListBox from the WPF Bag of Tricks:

This allows the user to drag a ListBoxItem to move it in the list and reorder the items.  

My ReorderListBox.Source is bound to a property called Persons in my Window's ViewModel.  Persons is an ObservableCollection<Person>.

My DataTemplate for Person uses a Catel UserControl (called PersonEntry), backed by a ViewModel (PersonEntryViewModel).

The Person class has a Catel property called 'Row'.  The intent is that Row should always be identical to the Person's index in the collection.  The ViewModel also has a Row property which is mapped to Person.Row via Model and ViewModelToModel attributes.  Pretty standard stuff and it all works, until I drag one item to a different location in the list.  Once I do, all of my PersonEntryViewModels seem to disconnect the binding between their Row property and their model's Row property.  If I change the Person.Row value, the PersonEntryViewModel.Row value is not updated.  All other properties in the PersonEntryViewModel are still bound to their corresponding Model property.

It may be significant that I have my ReorderListBox setup to only allow dragging an item by clicking and dragging on the TextBlock that is bound to 'Row'.  

This is very tough to debug since I am not sure how to determine what is causing the binding to get removed.  Is there a way to track this?

Jul 19, 2012 at 8:04 PM

1) Row not updating => does it support INotifyPropertyChanged?

2) Probably the control disconnects the whole list => updates => reconnects the whole list to make sure it performs good. Can you provide a log file with LogManager.RegisterDebugListener() called?

Jul 20, 2012 at 2:50 AM

Hi Geert,

Where should I send the log file to?  I tried to add it to this reply, but it appears to be too long - I got an error when I clicked Save.  


Jul 20, 2012 at 1:49 PM

I sent the log to your email address.  Regarding your points above:

1) 'Row' is a property in my model and viewmodel.  Both derive from DataObjectBase so, yes, INotifyPropertyChanged is implemented.  The binding between the two works until an item is dragged in the ReorderListBox.

2) The control actually only disconnects the item that was dragged.  It then reconnects it, so that item does get a new ViewModel created.  I forgot to mention that this newly created ViewModel does maintain the Row binding, it is all of the others that don't.  The other ViewModel properties do maintain their binding to the model properties after the drag.

Jul 23, 2012 at 6:44 PM

Is this problem solved with the recent fix for the "NamedObject" phantom item?

Jul 23, 2012 at 8:14 PM

Unfortunately, no.  

Jul 23, 2012 at 8:15 PM

Is it possible for you to send me a (private) repro so I can debug it?

Jul 24, 2012 at 12:16 AM
Edited Jul 24, 2012 at 12:16 AM

Hi Geert,

I tried stripping this down to a very simple example, but in that case, everything works properly.  It would be difficult to send the full example as I can't send my entire project.  Is there some place in the Catel source code where I can put a breakpoint that would be called when a binding between a viewmodel property and model property is dstroyed?  That will help me determine what code is causing the binding to stop working.

Jul 25, 2012 at 1:39 PM

You can step through the source code in external projects as describe in this documentation. I recommend that you then search for UserControlLogic, that is the class that takes care of it "all".