我想在ComboBox按键中找到我的项目

时间:2014-07-29 12:48:17

标签: c# wpf combobox

你好,我已经搜索了很多这个问题但我发现它所以我来这里问我有这个代码:

<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,我将一个DataTable设置为DataContext,它来自一个select查询sql和&#34; uf&#34;是DataTable中列的名称,它在ComboBox中显示正常,但我希望当我按下某个键时,组合框将转到以此键开头的行,就像我只在ComboBoxItem中放入文本时那样。抱歉,我的英文!

1 个答案:

答案 0 :(得分:0)

尝试类似这样的例子:

<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