views:

44

answers:

1

I've got a list of ComboBoxes inside a listbox, like so:

    <ListBox ItemsSource="{Binding Values}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <ComboBox ItemsSource="{...}" IsTextSearchEnabled="True" IsEditable="True"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

The Values for my listbox ItemsSouce is defined in my ViewModel as

    public ObservableCollection<string> Values { get; set; }

How can I get the Text for each one of the ComboBoxes to show the Value for that particular ListBox item?

(i.e. if values is {"a", "b", "c"} I want a list of 3 comboboxes showing "a", "b" and "c")

+1  A: 

Try this.

<ListBox ItemsSource="{Binding Values}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <ComboBox Text="{Binding Mode=OneWay}" ... />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

The idea here being that the implied DataContext of the DataTemplate will be the current list box item. By specifying a Binding with no Path, you're binding the text to the value "a", "b", or "c".

Josh Einstein
Fantastic, thank you! I would have never guessed. :)
geosteve