![](/img/trans.png)
[英]How to fire the Combobox Selection Changed event if there's only 1 entry in the drop down
[英]How to have a combobox where the drop down shows two columns but the selection shows only one?
我会用谷歌搜索,但是我不知道如何用词表达来进行搜索。 我的问题很简单:我正在移植用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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.