我想要一个带有数字1-8的下拉列表,并将所选值绑定到类型为"NumberOfZones"的int属性。由于默认情况下,下拉列表返回字符串值,因此无法保存在int属性中。如何将其强制转换为int。
如何设置下拉列表项并进行整数选择。
<ComboBox Background="#FFB7B39D" Height="23" Name="cboNumZones" Width="74" Margin="158,16,368,247" Grid.Row="2" SelectionChanged="cboNumZones_SelectionChanged"
SelectedValue="{Binding Path=NumberOfZones, Mode=TwoWay}">
</ComboBox>
<!--
<ComboBoxItem >1</ComboBoxItem>
<ComboBoxItem >2</ComboBoxItem>
<ComboBoxItem >3</ComboBoxItem>
<ComboBoxItem >4</ComboBoxItem>
<ComboBoxItem >5</ComboBoxItem>
<ComboBoxItem >6</ComboBoxItem>
<ComboBoxItem >7</ComboBoxItem>
<ComboBoxItem >8</ComboBoxItem>
-->
包含NumberOfZones属性的对象是UserControl的DataContext。
非常感谢。