I know that there are many questions regarding DataBinding a combobox and also there are many tutorials but I feel those tutorials hard. So, I am asking this question.
Suppose I have two tables in my database:
Customer
CustomerID
Name
GenderID
GenderTypes
GenderTypeID
GenderType
I have created my models using ADO.Net Entity Data Model. So, I am using Entity Framework.
Now I have a ViewModel in which I declare a property called Customers as below:
private List<Customer> _customers;
public List<Customer> Customers
{
get
{
return _customers;
}
set
{
_customers = value;
OnPropertyChanged("Customers");
}
}
Now I have a View Like this:
<Window ......>
<Window.DataContext>
<vm:MainWindowViewModel />
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
..
..
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
..
..
</Grid.ColumnDefinitions>
<TextBlock Text="Name" ....../>
<TextBox Text="{Binding Name}"...../>
<TextBlock Text="Gender" ....../>
<TextBox ItemsSource="????"
SelectedValue="????"
SelectedValuePath="????"...../>
</Grid>
</Window>
I dont know how to bind the combobox, so that I can see Male and Female as the items of combobox and when I select I should get corresponding GenderID instead of GenderType.
I know this is a very simple and straight forward question but I am very much new to WPF and trying to learn it.