Resolved - The theme was interfering with the display
This is my first experience with WPF so there may be an obvious answer to this.
I'm trying to display a Month selection combobox where the month names are displayed, and when a selection is made the integer value is captured.
XAML
<ComboBox Margin="5" IsEditable="False"
IsEnabled="{Binding IsCompanyFileUploadPeriodEnabled}"
ItemsSource="{Binding StartMonths}"
DisplayMemberPath="Key"
SelectedValuePath="Value"
SelectedValue="{Binding SelectedStartMonthID}"
Width="50"></ComboBox>
Edit: The ViewModel extends the Galasoft MvvmLight ViewModelBase, which provides the RaisePropertyChanged method.
ViewModel
Dictionary<string, int> _startMonths;
public Dictionary<string, int> StartMonths
{
get
{
if (_startMonths == null)
{
_startMonths = new Dictionary<string, int>();
for (int i = 1; i < 13; i++)
{
_startMonths.Add(System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(i),
i);
}
}
return _startMonths;
}
}
int _selectedStartMonthID;
public int SelectedStartMonthID
{
get
{
return _selectedStartMonthID;
}
set
{
_selectedStartMonthID = value;
RaisePropertyChanged(() => SelectedStartMonthID);
}
}
But for some reason when I run the app the combobox is displaying as
- [January, 1]
- [February, 2]
- etc
Does anyone know why it might be ignoring the DisplayMemberPath instruction? The SelectedValuePath setting seems to be working fine when an element is selected.