【问题标题】:I want to found I item in the ComboBox pressing keys我想在 ComboBox 按键中找到 I 项
【发布时间】:2014-07-29 12:48:17
【问题描述】:

你好,我搜索了很多关于这个问题,但我没有找到,所以我来这里问我有这个代码:

<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 设置了一个来自选择查询 sql 的 DataTable,“uf”是 DataTable 中列的名称,它在 ComboBox 上显示正常,但我希望当我按下一些键组合框转到以该键开头的行,就像我将文本放入 ComboBoxItem 时一样。对不起我的英语!

【问题讨论】:

    标签: c# wpf combobox


    【解决方案1】:

    试试这个例子:

    <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>
    

    来自here的代码

    另一个使用 Combobox.ItemTemplate 的例子

    <ComboBox TextSearch.TextPath="Name" ItemsSource="{Binding Persons, ElementName=Window}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Name}"/>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>
    

    来自here

    【讨论】:

    • 非常感谢,真的很好用!!再次感谢您
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 2011-08-05
    • 1970-01-01
    • 2018-04-17
    • 2020-06-14
    • 1970-01-01
    • 2020-09-14
    相关资源
    最近更新 更多