首页 > 解决方案 > 访问 WPF 组合框中对象的名称

问题描述

我在 WPF 中有一个 ComboBox,在我的数据库中有一个表(Trainer)。它们按如下方式链接在一起:

comboTrain.ItemsSource = (from t in ctx.Trainers select t).ToList<Trainer>();

另外,我将它绑定在 xaml 中,如下所示:

<ComboBox x:Name="comboTrain" ItemsSource="{Binding TrainerCollect}" 
          DisplayMemberPath="Name" SelectedValuePath="TrainerId"/>

因此,当我运行应用程序时,我会在 ComboBox 中看到所有培训师的姓名。现在,我只想显示在 ComboBox 中选择的培训师的姓名。

我怎样才能做到这一点?

标签: databasewpfcombobox

解决方案


我为我的问题找到了解决方案:使用“comboTrain.Text”我可以将所选项目作为字符串获取。


推荐阅读