Search code examples
wpftoolkititemtemplateautocompletebox

WPF Toolkit autocompletebox itemtemplate


I'm following this reference to implement an autocomplete textbox in my application: http://www.broculos.net/2014/04/wpf-autocompletebox-autocomplete-text.html

I notice there is a difference when using an itemtemplate vs not using one. When using a template the items have more space between them. I need to use the itemtemplate but how can I make it look more like when not using a template, move the items closer to each other?


Solution

  • When not using an ItemTemplate, the single items in the dropdown list will be simple strings and will be represented by TextBlocks in the UI. TextBlocks don't have any margin by default, so the lines are close together.

    Assigning an ItemTemplate will replace this visual appearance (with whatever the ItemTemplate defines). Most probably there is some margin/padding defined in the ItemTemplate, e.g. if an Label is used as representation (Labels have some default margin assigned).

    Changing the margin/padding properties of the single elements of your ItemTemplate should help here.