I'm kind of new to wpf and data binding and I'm stuck on this.
So basically I have a table of EyeColors and EyeColorIds. Eye Color Id is a foreign key of a Person table.
I created a combobox that is bound to the EyeColor table which populate it with the possible eye colors. However when a user edits a person I want the person's eye color to already be selected. How can I do this?
<ComboBox
DataContext="{StaticResource tblEyeColorViewSource}"
Height="23"
HorizontalAlignment="Left"
Margin="95,125,0,0"
Name="EColorBox"
VerticalAlignment="Top"
Width="120"
DisplayMemberPath="EyeColor"
ItemsSource="{Binding}" />
That is my xaml for the combobox. The eye color of the specific person is obtained when the window is constructed.
So before I create my edit window, i take the data from the datagrid and make a person object
then i construct the edit window
public AddEditForm(PeopleManagerController pmc, Person p)
{
controller = pmc;
InitializeComponent();
personToAE = p;
FnameText.DataContext = personToAE;
LnameText.DataContext = personToAE;
datePicker1.DataContext = personToAE;
datePicker1.Text = personToAE.DateOfBirth;
AddEditButton.Content = "Edit";
}
Then when the user clicks the edit button it sends the person to edit to the controller class for SQL transaction.
As for the xaml, I'm just creating controls and binding them to the person object properties. I want the eye color property of the person to edit to be the selected value of the combobox.