CSLA MVVM Silverlight DynamicListBase

CSLA MVVM Silverlight DynamicListBase

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

Ziad posted on Tuesday, May 10, 2011


Let us suppose that I have the following two classes in my model:

       1. Person : BusinessBase<Person>

       2. Persons : DynamicListBase<Person>

Then, in my view model I define the following class :

      1. PersonsVM : ViewModel<Persons>, in this class I call the static method found in the model Persons.

I bind the variable Model (found in the viewmodel PersonsVM) to my Silverlight DataGrid.

As you can notice that my model Persons is a DynamicListBase, this means that whenever the user modifies a line in the DataGrid, the DataPortal_Update will be called automatically... and this works fine.

But this doesn't work, on datagrid columns that have a dataTemplate, for example:




<TextBox  Text={Binding Path=Model.Name, Mode=TwoWay} >




In the above column, if a change the value found in the textbox and then press enter, the DataPortal_Update is not called...

My above column template is easy, I know that I can replace it by DataGridTextColumn, but actually I use TemplateColumns for comboboxes ...



RockfordLhotka replied on Tuesday, May 10, 2011

DynamicListBase (DLB) relies on the datagrid control calling the appropriate data binding methods on the IEditableObject interface. If the datagrid control doesn't do the right thing (and maybe the SL one doesn't with templated columns, I don't know), then there's nothing DLB can do about that.

If the datagrid doesn't call EndEdit when the user leaves the row, the DLB has absolutely no way of knowing that the user left the row, so it doesn't know to save the object.

So if the datagrid doesn't call EndEdit as expected, then you will need to create a subclass of the datagrid control, or some other UI code, and make that call yourself.

Copyright (c) Marimer LLC