Reputation: 10162
I have a ComboBox
:
<ComboBox Grid.Column="1" Grid.Row="9" SelectedValue="{Binding SelectedReason}">
<ComboBoxItem Content="Bug Report" IsSelected="True"/>
<ComboBoxItem Content="Suggestion"/>
<ComboBoxItem Content="Complaint"/>
<ComboBoxItem Content="Other"/>
</ComboBox>
...which binds to a Property
:
private string _selectedReason;
public string SelectedReason
{
get { return _selectedReason; }
set
{
if (_selectedReason == value)
{
return;
}
_selectedReason = value;
OnPropertyChanged("SelectedReason");
}
}
When I output the value
, instead of showing something like:
Bug Report
Suggestion
...I get:
System.Windows.Controls.ComboBoxItem: Bug Report
System.Windows.Controls.ComboBoxItem: Suggestion
I tried using SelectedItem
instead, but the result is the same. All I want is the value and not the control type. Any ideas what's going on?
Upvotes: 1
Views: 187
Reputation: 19296
You should set SelectedValuePath
to Content
:
<ComboBox Grid.Column="1" Grid.Row="9" SelectedValue="{Binding SelectedReason}"
SelectedValuePath="Content">
<ComboBoxItem Content="Bug Report" IsSelected="True"/>
<ComboBoxItem Content="Suggestion"/>
<ComboBoxItem Content="Complaint"/>
<ComboBoxItem Content="Other"/>
</ComboBox>
Upvotes: 2