Suppose we have a WPF ComboBox and want to populate it using ObjectDataProvider.
<ObjectDataProvider ObjectType="{x:Type provider:DataProviderProxy}" x:Key="BLDataProvider">
</ObjectDataProvider>
<ObjectDataProvider x:Key="InstallDriverProvider"
ObjectInstance="{StaticResource BLDataProvider}"
MethodName="GetInstallDrivers"
IsAsynchronous="True">
</ObjectDataProvider>
<ComboBox Grid.Row="0" Grid.Column="1"
IsEditable="False"
AlternationCount="2"
IsTextSearchEnabled="True"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource InstallDriverProvider}}"
SelectedItem="{Binding Path=InstallDriverPlugin, Mode=TwoWay}"
SelectedValue="{Binding Path=InstallDriverPlugin.Name, Mode=TwoWay}"
SelectedValuePath="id"
...
If the GetInstallDrivers() method calls some server method that returns asynchronously like a response from web service how it would be possible to populate the combobox?
How to populate the combobox after the response has arrived?
If you want to populate the combo box asynchronously, then it’s not the best idea to use ObjectDataProvider. But instead use a ViewModel (and the MVVM pattern), which has the combobox datasource as an observable collection member property. Then simply get the data asyncrhrounously, then post it to the UI thread and fill the collection.