I have a list containing instances of the following class:
namespace Foo.InformationModel.Reference
{
public class ReferenceCodeTypeChar
{
public ReferenceCodeTypeChar();
public string Category { get; set; }
public string CodeValue { get; set; }
public string Description { get; set; }
public string Value { get; set; }
}
}
Here is the object that is used as the DataContext
for the window in which the combobox is and its related properties:
public class MyObject
{
public List<Foo.InformationModel.Reference.ReferenceCodeTypeChar> ProgramTypes() {...}
private string _selectedProgramTypeCode;
public string SelectedProgramTypeCode
{
get
{
return _selectedProgramTypeCode;
}
set
{
if (_selectedProgramTypeCode != value)
{
_selectedProgramTypeCode = value;
OnPropertyChanged("SelectedProgramTypeCode");
}
}
}
}
Here is the xaml code behind for the combobox:
<ComboBox ItemsSource="{Binding Path=ProgramTypes}"
SelectedItem="{Binding Path=SelectedProgramTypeCode, Mode=TwoWay}"
DisplayMemberPath="Description"
SelectedValuePath="Value"/>
The problem happens inside SelectedProgramTypeCode. The value of the "value" variable is Foo.InformationModel.Reference.ReferenceCodeTypeChar instead of the expected string of Value property of the ReferenceCodeTypeChar object. What is wrong?