【问题标题】:WPF ComboBox using letter keys for selecting itemsWPF ComboBox 使用字母键选择项目
【发布时间】:2014-07-02 00:28:45
【问题描述】:

我的应用程序中有一个组合框,当下拉菜单打开时,我希望用户能够键入字母并让下拉菜单跳到该选项。目前它不会跳到选择。我查找了几个 stackoverflow 问题并应用了他们提到的更改

IsTextSearchEnabled="True" TextSearch.TextPath="{Binding Name}"

WPF ComboBox using shortcut keys for selecting items

How to select item by typing a keyboard letter key in WPF combobox?

<ComboBox x:Name="serviceSelection" Grid.Row="0" Grid.Column="1"
                                          IsTextSearchEnabled="True"
                                         TextSearch.TextPath="{Binding Name}"
                                          VerticalAlignment="Top"
                                          Height="25"
                                          HorizontalAlignment="Right"
                                          Width="210"
                                          ItemsSource="{Binding ServiceRootNodes}"
                                          SelectionChanged="ServiceSelection_SelectionChanged"
                                          SelectedIndex="0">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>                                               
                                            <TextBlock Text="{Binding Name}" />
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                </ComboBox>

有人可以就我做错了什么向我提供建议/反馈吗?还有在哪些情况下,comboxBox 字母搜索不起作用?

【问题讨论】:

  • 发现我的错误:应该只是 TextSearch.TextPath="Name"

标签: c# wpf xaml combobox wpf-controls


【解决方案1】:
【解决方案2】:

尝试给出属性名称而不是绑定

TextSearch.TextPath="名称"

【讨论】:

  • 这似乎是一个解决方案。如果您查看原始帖子的 cmets,您会注意到作者本人也得出了相同的解决方案。
猜你喜欢
  • 1970-01-01
  • 2016-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-30
  • 2011-01-13
  • 2015-11-08
  • 1970-01-01
相关资源
最近更新 更多