Generally, what you want to do with this is to build your ItemsSource, and once that's done, specify the SelectedItem. For example, you could have a class like this:
namespace
WpfComboBox {
class MainWindowViewModel {
public NorthwindIBEntities mgr;
public ObservableCollection<Employee> Employees { get; private set; }
public Employee CurrentEmployee;
public Employee CurrentManager;
public MainWindowViewModel() {
Employees =
new ObservableCollection<Employee>();
mgr =
new NorthwindIBEntities();
var query = mgr.Employees.ExecuteAsync(op => op.Results.ForEach(Employees.Add));
CurrentEmployee = mgr.Employees.FirstOrDefault();
CurrentManager = GetManager(CurrentEmployee);
}
private Employee GetManager(Employee theEmployee) {
int ManagerID = (int)theEmployee.ReportsToEmployeeID;
var query = mgr.Employees.Where(c => c.EmployeeID.Equals(ManagerID));
return query.FirstOrDefault();
}
}
}
And then, in your code for the display:
public MainWindow() {
InitializeComponent();
view =
new MainWindowViewModel();
comboBox1.ItemsSource = view.Employees;
comboBox1.DisplayMemberPath =
Employee.PathFor(e => e.MyFirstName);
comboBox1.SelectedItem = view.CurrentManager;
}
There's a pretty good sample showing ComboBox population in Silverlight, in the DRC. You can find that at http://drc.ideablade.com/xwiki/bin/view/Documentation/SimpleComboBox