takayoshi takayoshi - 1 year ago 185
C# Question

wpf combobox with custom itemtemplate text

I have

with custom

<ComboBox Height="20" Width="200"
SelectedItem="{Binding Path=SelectedDesign}"
ItemsSource="{Binding Path=Designs}" HorizontalAlignment="Left"

<DataTemplate DataType="{x:Type formdesign:FormDesignContainer}">
<Rectangle Width="200" Height="100">
<ImageBrush ImageSource="{Binding Path=ImageThumb}" Stretch="Uniform" />


This works well. However WPF tries to draw rectangle as Combobox Text. How can I set "text" for this template. By "text" I mean string or control which represent selected item and write into combobox when item is selected

In other words I'd like to do this:

enter image description here

But now I got this

enter image description here

Answer Source

Try setting SelectionBoxItemTemplate with a TextBlock. Appears that SelectionBoxItemTemplate is read-only. So another approach is to override ItemContainerStyle.Template. Example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download