Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ComboBox ItemTemplate binding to a string collection

I have a combobox in wpf which is bound to a List<string>. All works well, but now for some reason I need to bind to an item template. The XAML for the combo box is

<ComboBox ItemsSource="{Binding Tracks}" SelectedItem="{Binding SelectedTrack}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding **WhatShouldBeHere**}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

If my data source is a custom collection then binding is easy, I should just pass the property name from custom collection, but as the binding source is a list of string, what should the binding property be?.

like image 462
Manvinder Avatar asked Oct 01 '14 10:10

Manvinder


1 Answers

It should be

<TextBlock Text="{Binding}"/>

which is equivalent to

<TextBlock Text="{Binding Path=.}"/>

See the Remarks section on the Binding.Path MSDN page for further details.

like image 133
Clemens Avatar answered Sep 18 '22 11:09

Clemens