Hi,
in WPF if you don't use the binding infrastructure then you are missing a lot.
In the following sample I tried to mimic your case, and use the binding to do exactly that,
the only drawback is that the customers data are present on the client, they are not fetched from the server on demand
1. make sure to create a class that represents your model,
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
2. pack your class instances in a list (in my sample an IEnumerable of customers)
3. give that collection to the items source property of the combobox at the load event,
Loaded += (sender, args) => {
var customers = from i in Enumerable.Range(1, 10)
select
new Customer() {
Id = i,
Name = "Customer " + i.ToString(),
Age = i + 20};
comboBox1.ItemsSource = customers;
};
by this you have a combobox that is populated by that list, each combobox item will print the type name you created --> the default behavior is to call ToString, you have 2 solutions here,
first --> go back to your custom class and override ToString to just return the Id,
second --> make use of the DisplayMemberPath of the combobox by giving it the property to display
<combobox height="23" displaymemberpath="Id" horizontalalignment="Left" .../>
now we have the data in the UI, we will use the binding to glue everything together.
<textbox height="23" text="{Binding ElementName=comboBox1, Path=SelectedItem.Name}" .../>
<textbox height="23" text="{Binding ElementName=comboBox1, Path=SelectedItem.Age}" .../>
Now whenever the combo box selected item change, both text boxes will be updated.
hope this solution is helpful to you.