BO Async call returns before observable collection loads

BO Async call returns before observable collection loads

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


Vlam posted on Friday, December 09, 2011

We are using silverlight 4. Csla 4.2 Bxf and MVVM design pattern

I am fairly new to csla and Silverlight,  and I am struggling to get my comboBox to bind correctly to my observable collection in my viewmodel.

My viewmodel’s constructor calls the beginRefresh method to create a new participant.

 

    public class ParticipantVM : ViewModel<Participant>

    {

 

        public ParticipantVM()

        {

            BeginRefresh("NewParticipant”);

        }

}

 

Within that viewmodel I also got an observable collection that loads all the countries from the database so that it can be bound to a new participant.

public ObservableCollection<CountryListVM> CountryList

        {

            get

            {

                var result = new ObservableCollection<CountryListVM>();

                result.Add(new CountryListVM());

                return result;

            }

        }

 

It seems like the fetch of the countries does not always complete before the overridden onrefreshed is called by the viewmodel and when that happens the countries are not bound to the country of residence property on the participant object

 

My Xaml for the combo box is the following:

<ComboBox  Grid.Column="1" Grid.Row="10" Name="cboCOR" Margin="5" ItemsSource="{Binding Source={StaticResource participantVMCountryListModelViewSource}}" SelectedValuePath="Country_Name" DisplayMemberPath="Country_Name" SelectedValue="{Binding Path=Model.Country_of_Residence, Mode=TwoWay}" />

 

Sometime it will load fine and the cansave property of the participantVM would be true when I select a country in the list but then other times the cansave will stay false even though I would select a value in the combo box as if combobox is not bound to the property of my viewModel at all.

 

JonnyBee replied on Friday, December 09, 2011

I'd recommend to switch to a UOW approach to avoid these syncronization issues.

Read more here:
http://forums.lhotka.net/forums/p/10508/49156.aspx 
http://forums.lhotka.net/forums/p/10030/47059.aspx
http://forums.lhotka.net/forums/t/9863.aspx

Basically - create e ReadOnly object to fetche the root object and all other name/value lists (all of them) in one fetch from the server and then create/connect the viewmodels. All data will then be available when you create the view and viewmodels.

Copyright (c) Marimer LLC