我想在组合框中按下键找到我的项目
本文关键字:我的 项目 组合 | 更新日期: 2023-09-27 18:15:29
你好,我已经搜索了很多这个问题,我没有找到它,所以我来问这里我有这个代码:
<ComboBox TabIndex="10" x:Name="cbo_uf" HorizontalAlignment="Left" Margin="69,76,0,0" VerticalAlignment="Top" Width="52" Foreground="#FF4C63CB" ItemsSource="{Binding}" SelectionChanged="cbo_uf_SelectionChanged" Grid.RowSpan="3" Height="23">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding uf}" Width="50" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
为了填充这个ComboBox,我将DataContext设置为来自select查询sql的数据表,"uf"是数据表中列的名称,它在ComboBox中显示正常,但我想当我按下某些键时,组合框会转到以该键开始的行,就像我在ComboBoxItem中放入文本时发生的那样。对不起,我的英语不好!
试试下面这个例子:
<ComboBox IsEditable="true" TextSearch.TextPath="Name">
<Image Name="Cat" Source="data'cat.png"/>
<Image Name="Dog" Source="data'dog.png"/>
<Image Name="Fish" Source="data'fish.png"/>
</ComboBox>
此处的代码
另一个关于组合框的例子。ItemTemplate
<ComboBox TextSearch.TextPath="Name" ItemsSource="{Binding Persons, ElementName=Window}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
从这里