您可以完全按照示例中的方式指定您的选择。要使其正常工作,您缺少的是SelectedValuePath属性。如果没有它,SelectedValue将与SelectedItem相同。通过在ComboBox中设置SelectedValuePath=“Content”,您可以指定SelectedValue绑定只绑定到SelectedItem的一部分,在本例中是您指定为每个ComboBoxItem中的内容的Int内容。
这里有一个小的演示,它还将值绑定到一个文本框,您可以在其中设置该项,并通过SelectedValue绑定(反之亦然)查看它在组合框中的反映。
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Set Value:" />
<TextBox Text="{Binding MyIntProperty, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Select Value:" />
<ComboBox SelectedValue="{Binding MyIntProperty}" SelectedValuePath="Content">
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>6</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>