我会用谷歌搜索这个,但我不知道如何用词来进行搜索。我的问题很简单:我正在移植一个用 Access 编写的应用程序,其中一个窗体上有一个组合框。当您打开下拉菜单时,它会显示两列信息:左侧是缩写,右侧是全名。但是,当您选择一个时,组合框中的所选选项(下拉列表已关闭)仅显示缩写。知道如何在 WPF 中实现这一点吗?
最佳答案
这是在 XAML 中执行此操作的另一种方法。重要的部分是 TextSearch.TextPath。这将搜索具有指定名称的对象。在这种情况下,它是名为“Foo”的字符串。
<ComboBox Name="cmbBox" ItemsSource="{Binding Test}" Height="25" IsEditable="True" IsReadOnly="True" TextSearch.TextPath="Foo">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" TextSearch.Text="{Binding Path=Bar}">
<TextBlock Text="{Binding Path=Foo}"/>
<TextBlock Text="{Binding Path=Bar}" Margin="10 0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
要以编程方式设置 TextSearch,您只需:
cmbBox.SetValue(TextSearch.TextPathProperty, "Foo");
关于c# - 如何有一个下拉列表显示两列但选择只显示一列的组合框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9154079/