CSLA 4 RC0 - binding issue?

CSLA 4 RC0 - binding issue?

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

Ranjini posted on Thursday, July 15, 2010

Tools: CSLA 4 RC0/ Silverlight 4

I posted regarding the same scenario before, but my problem now is different.

I have a BB-> BLB scenario. In the UI, I have a tabbed interface that presents the user with different child objects of the BB and allows the user to make changes. One of the child objects of the BB is a BLB, and one of the tabs presents a datagrid - > dataform type master-detail interface to edit and add items in the BLB. Here is the XAML binding for this part

<controls:TabControl x:Name="tcDomainEdit" DataContext="{Binding Source={StaticResource domainEditModel}}">

  <controls:TabItem Header="Custom Properties"   DataContext="{Binding Model}">

    <StackPanel Orientation="Vertical">

<Button x:Name="btnAddCP" Content="Add Custom Property" />

<csla:TriggerAction Name="AddCustomPropertyTrigger" Height="0" Width="0" DataContext="{Binding Source={StaticResource domainEditModel}}" TargetControl="{Binding ElementName=btnAddCP}" MethodName="AddCustomProperty" TriggerEvent="Click" MethodParameter="{Binding ElementName=dfDomainCPEdit, Path=CurrentAddItem}" />

       <data:DataGrid x:Name="dgCustomPropertyType"  Tag="{Binding}"  AutoGenerateColumns="False"  ItemsSource="{Binding CustomPropertyTypes, Mode=TwoWay}" 

SelectedItem="{Binding CurrentItem,ElementName=dfDomainCPEdit, Mode=TwoWay}">


              <data:DataGridTextColumn  Binding="{Binding Name, Mode=TwoWay}" />

              <data:DataGridTextColumn Binding="{Binding Alias, Mode=TwoWay}"/>

              <data:DataGridTextColumn Binding="{Binding Description, Mode=TwoWay}" />



       <df:DataForm x:Name="dfDomainCPEdit"   Margin="5,5,5,5" AutoEdit="True" AutoCommit="True" AutoGenerateFields="True" ItemsSource="{Binding CustomPropertyTypes, Mode=TwoWay}" CurrentIndex="{Binding Source={StaticResource domainEditModel}, Path= CustomPropertyTypeSelected, Mode=TwoWay}" />





<StackPanel Grid.Row="10" Orientation="Horizontal" Grid.ColumnSpan="2"  DataContext="{Binding Source={StaticResource domainEditModel}}">

   <Button Content="Save" Height="23" Name="SaveButton" Width="75" Margin="5" IsEnabled="{Binding Path=CanSave}" />

   <Button Content="Cancel" Height="23" Name="CancelButton" Width="75" Margin="5" IsEnabled="{Binding Path=CanCancel}" />

   <csla:TriggerAction Height="0" Name="SaveTrigger" Width="0" TargetControl="{Binding ElementName=SaveButton}" MethodName="Save" />

   <csla:TriggerAction Height="0" Name="CancelTrigger" Width="0" MethodName="Cancel" TargetControl="{Binding ElementName=CancelButton}" />





  The triggerevent for the Add button is defined as follows –

public void AddCustomProperty(object sender, Csla.Xaml.ExecuteEventArgs e)



            Model.CustomPropertyTypes[this.Model.CustomPropertyTypes.Count - 1].Name = "CustomPropertyType" + this.Model.CustomPropertyTypes.Count.ToString();

            CustomPropertyTypeSelected = this.Model.CustomPropertyTypes.Count - 1;



There is really not much else that controls the behavior of this section of the page.

My problem is that, when I first add an item, the item immediately shows up on the grid and the dataform as the current item (as expected). I can then Save the item (Save is enabled at this point). Once I save, if I continue to add another item, the Save gets enabled correctly, but the new added item doesn’t show up on the grid and hence the dataform is empty as well.  If I tab away and come back, the new element shows up, but doesn’t otherwise.

What am I doing wrong? Any help is appreciated.


Ranjini replied on Friday, July 16, 2010

Any help please?

Ranjini replied on Monday, July 19, 2010

Making one last attempt to see if i can get any response to this?!

RockfordLhotka replied on Monday, July 19, 2010

My recommendation is to eliminate CSLA from the picture.

Create an ObservableCollection<T> of some type (string or whatever). Bind it to the datagrid. Add items to the collection and see if they appear in the datagrid as expected.

While it is possible there's a bug in BusinessListBase, it is equally possible that there's a bug in the datagrid control - even on Silverlight that control has been slow to stabilize, and don't even get me started on the almost impossibly bad quality the datagrid represents on the WPF side...

Ranjini replied on Monday, July 19, 2010

Thanks for the recommendation. At the very least, it opened me up to the possibility that this might be a Silverlight problem. Without much hope of any quick success, I had several things in mind I wanted to try -

1) eliminate CSLA and use observablecollection (your suggestion)

2) eliminate childwindow ( since there are some known quirks with that when some controls are embedded in it)

3) eliminate tabcontrol

4) examine datagrid and see if there were alternatives

4) a combination of the above

and  voila ! it was option (3). When i took the datagrid/dataform pair outside of the tabcontrol but still within the child window, everything worked as expected!

Anyway, I am for now cheating by binding the SelectedTab property of the tabcontrol to the viewmodel and everytime i add or remove items from the child list, i reset it to 0 and then bring it back again to the last current index value and that seems to work!

Thanks much for nudging me in this direction!


Copyright (c) Marimer LLC