Hi Jeremy, One way could be to have a property in the ViewModel like this:
private int _selectedIndex = -1;
public int SelectedIndex
{
get { return _selectedIndex; }
set
{
if (value != _selectedIndex)
{
_selectedIndex = value;
NotifyPropertyChanged("SelectedIndex");
}
}
}
It's set to -1 initially so the XAML doesn't throw an error when there's no collection to bind to. Bind it to the list box:
<ListBox ItemsSource="{Binding Employees}" SelectedIndex="{Binding SelectedIndex}" />
Then, in the completed event (when the service returns from the asynchronous call with the data) you can set it to whatever you want.
void svcClient_GetDataCompleted(object sender, EmployeeSvc.GetDataCompletedEventArgs e)
{
Employees = e.Result;
SelectedIndex = 1;
}
Not particularly elegant, but it seems to work. Cheers.