Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Select ComboBox value by typing when using DataTemplate

I have a combobox in wpf which is binded to some property (another object). Because I need to show two properties of that object i used DataTemplate inside combobox. Now when combobox is in focus I can't select some value by typing few starting letters (without DataTemplate it is possible).

<ComboBox Height="23" HorizontalAlignment="Left" Margin="104,14,0,0" Name="tipDokumentaCombo" VerticalAlignment="Top" Width="241" TabIndex="0" ItemsSource="{Binding Path=TipoviDokumenta}" SelectedValue="{Binding Path=Potvrda.Tip}" SelectedValuePath="Tip" SelectionChanged="tipDokumentaCombo_SelectionChanged">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Tip}" />
                        <TextBlock Text=" (" />
                        <TextBlock Text="{Binding Path=OpisDokumenta}" />
                        <TextBlock Text=")" />
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
like image 801
mersadk Avatar asked Mar 19 '26 13:03

mersadk


1 Answers

Set TextSearch.TextPath to the property that should be searched.

Update
Because the abvove solution seems not to work for you, try to set the search text manually for the container:

<ComboBox.ItemContainerStyle>    
   <Style TargetType="{x:Type ComboBoxItem}">        
          <Setter Property="TextSearch.Text" Value="{Binding Tip}" />            
    </Style>
</ComboBox.ItemContainerStyle>
like image 106
HCL Avatar answered Mar 22 '26 01:03

HCL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!