我想检索在组合框中选择的字符串值并将其转换为整数,但是 SelectedItem 方法总是返回对象的名称。其他帖子建议使用 SelectedItem 的 Content 属性,但在使用 .net 4.6.1 的 vs2017 中我无法使用它。有人可以帮助我在不解析字符串的情况下获取值吗?
这是 Xaml,后跟 cs 文件:
<ComboBox x:Name="Combo_BaudRate" SelectedValuePath="Content"
HorizontalAlignment="Left" VerticalAlignment="Top"
Width="120" Margin="112,81,0,0"
SelectionChanged="ComboBox_SelectionChanged"
IsReadOnly="True" >
<ComboBoxItem Content="1200" />
<ComboBoxItem Content="2400" />
<ComboBoxItem Content="4800" />
<ComboBoxItem Content="9600" />
<ComboBoxItem Content="38400" />
</ComboBox>
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Selected_Port_Baudrate = Combo_BaudRate.SelectedItem.ToString();
}
呼啦一阵风
慕沐林林
随时随地看视频慕课网APP
相关分类