WPF组合框问题
本文关键字:问题 组合 WPF | 更新日期: 2023-09-27 18:26:25
这只是一个简单的问题。
我有两个组合框,其中一个有硬编码的数据:
<ComboBox>
<ComboBoxItem/>
</ComboBox>
当我尝试在SelectionChanged上使用case语句时,我从Convert.ToString(cboForm.SelectedValue): "System.Windows.Controls.ComboBoxItem: Directional Bore"
获得一个值。
现在,在同一个表单上,我有另一个组合框,其中包含我正在用comboboc.items.add()
填充的数据,SelectionChanged之后该组合框的值是实际的文本值。
我能做些什么来避免"System.Windows.Controls.ComboBoxItem: "
处于选定值中吗?
案例陈述:
string caseSwitch = cboForm.SelectedValue.ToString();
switch (caseSwitch)
{
case "System.Windows.Controls.ComboBoxItem: Directional Bore":
{
ReportClass.DirBoreReport("","","");
cboForm.SelectedIndex = -1;
//MainAccess.Mw.SpecificForm = false;
//MainAccess.Mw.frmPage.Height = 4400;
//MainAccess.Mw.HoldPage = new Uri("DirectionalBore_Combined.xaml", UriKind.Relative);
//if (NavigationService != null) NavigationService.Source = MainAccess.Mw.HoldPage;
//MainAccess.Mw.SectionBar_DirectionalBore.Visibility = Visibility.Visible;
//MainAccess.Mw.scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
//MainAccess.Mw.lblForm.Content = "DIRECTIONAL BORE";
//MainAccess.Mw.Sbar = MainAccess.Mw.SectionBar_DirectionalBore;
break;
}
}
Xaml:
<ComboBox x:Name="cboForm" TabIndex="3" HorizontalAlignment="Left" Margin="746,618,0,0" VerticalAlignment="Top" Width="630" FontSize="48" FontWeight="Bold" Height="74" SelectionChanged="cboForm_SelectionChanged" >
<ComboBoxItem Content="Directional Bore" HorizontalAlignment="Left" />
<ComboBoxItem Content="Drain Tile Break" HorizontalAlignment="Left"/>
<ComboBoxItem Content="Fiber Installation" HorizontalAlignment="Left"/>
</ComboBox>
谢谢!
首先将SelectedItem
转换为ComboBoxItem
,然后ComboBoxItem.Content
将具有字符串值。
ComboBoxItem item = this.cboForm.SelectedItem as ComboBoxItem;
if (item != null)
{
MessageBox.Show(item.Content.ToString());
}