I have added a form on an RIA project that I am working on with three combo boxes that are filled using the domain data source. The problem is the form data already exists at the client when I open the child window. This means the combo box selected value is set prior to the item source being set and as such the combo box always uses the first item in the selection and also shows the record as being changed. Both are a problem... I ran across this post which suggested moving the domain data source into the resource section of the XAML but that did not seem to solve the problem. What I ended up doing is waiting for the domain data source to load and then setting the form data context as below.
<controls:ChildWindow.Resources>
<riaControls:DomainDataSource x:Key="dds_countries"
QueryName="GetCountries"
AutoLoad="True">
<riaControls:DomainDataSource.DomainContext>
<l:rtDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<riaControls:DomainDataSource x:Key="dds_states"
QueryName="GetStates"
AutoLoad="True">
<riaControls:DomainDataSource.DomainContext>
<l:rtDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<riaControls:DomainDataSource x:Key="dds_residencetypes"
QueryName="GetResidenceType"
AutoLoad="True">
<riaControls:DomainDataSource.DomainContext>
<l:rtDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
</controls:ChildWindow.Resources>
<ComboBox Grid.Row="3"
Margin="3"
Grid.Column="1"
DisplayMemberPath="Name"
SelectedValuePath="Type"
ItemsSource="{Binding Path=Data, Source={StaticResource dds_residencetypes}}"
SelectedValue="{Binding Path=ResidenceType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox Grid.Row="7"
Margin="3"
Grid.Column="3"
DisplayMemberPath="Name"
SelectedValuePath="Abbreviation"
ItemsSource="{Binding Path=Data, Source={StaticResource dds_states}}"
SelectedValue="{Binding Path=State, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox Grid.Row="8"
Margin="3"
Grid.Column="3"
DisplayMemberPath="Name"
SelectedValuePath="Name"
ItemsSource="{Binding Path=Data, Source={StaticResource dds_countries}}"
SelectedValue="{Binding Path=Country, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
private int LoadCount = 3;
private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
((DomainDataSource)this.Resources["dds_countries"]).LoadedData += (s, a) => { this.LoadAddress(); };
((DomainDataSource)this.Resources["dds_states"]).LoadedData += (s, a) => { this.LoadAddress(); };
((DomainDataSource)this.Resources["dds_residencetypes"]).LoadedData += (s, a) => { this.LoadAddress(); }; }
private void LoadAddress()
{
if (--this.LoadCount == 0)
{
this.LayoutRoot.DataContext = this.Address;
((System.ComponentModel.INotifyPropertyChanged)this.Address).PropertyChanged += (s, a) =>
{
this.OKButton.Visibility = System.Windows.Visibility.Visible;
};
}
}
first test
second test
third test