我有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>
...绑定到Property
:
private string _selectedReason;
public string SelectedReason
{
get { return _selectedReason; }
set
{
if (_selectedReason == value)
{
return;
}
_selectedReason = value;
OnPropertyChanged("SelectedReason");
}
}
当我输出value
时,而不是显示如下内容:
Bug Report
Suggestion
......我明白了:
System.Windows.Controls.ComboBoxItem: Bug Report
System.Windows.Controls.ComboBoxItem: Suggestion
我尝试使用SelectedItem
代替,但结果是一样的。我想要的只是价值而不是控制类型。有什么想法会发生什么?
答案 0 :(得分:2)
您应该将SelectedValuePath
设置为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>