Nate
Nate

Reputation: 30636

Combobox Databinding as an element inside of a Listbox in WPF

I'm having trouble with a combox databinding, this is what I'm trying to have it setup like:

1) Combo box is an item inside of a ListBox control [working]

2) Combo box's "Text" should be bound to a value from the ListBox ItemsSouce [not working]

3) The combo box will have an itemssource bound to a list that is retreived from a database [working]

Other items in this ListBox databind correctly, it is only the Combo Box I'm struggling with.

This is my xaml, any help is greatly appreciated.

<ComboBox 
    ItemsSource="{Binding Source={StaticResource ODPTaskCategories}}"
    Text="{Binding Path=Category}"
    FontFamily="Tahoma" 
    FontSize="14" 
    Height="24.91" 
    Margin="278,66.96,8,0" 
    Name="ddlCategory" 
    VerticalAlignment="Top" 
    VerticalContentAlignment="Center" 
    HorizontalAlignment="Stretch" 
    Width="Auto" 
    SelectionChanged="ddlCategory_SelectionChanged"  />

The objective is to allow the user to choose an item from the Combo Box from a pre-defined list and have that databound to the ListBox's databound item.

Upvotes: 1

Views: 1257

Answers (1)

Lars Truijens
Lars Truijens

Reputation: 43587

Check out the SelectedItem property. Also the order seems to matter.

<ComboBox 
    SelectedItem="{Binding Path=Category}"
    ItemsSource="{Binding Source={StaticResource ODPTaskCategories}}"
    FontFamily="Tahoma" 
    FontSize="14" 
    Height="24.91" 
    Margin="278,66.96,8,0" 
    Name="ddlCategory" 
    VerticalAlignment="Top" 
    VerticalContentAlignment="Center" 
    HorizontalAlignment="Stretch" 
    Width="Auto" 
    SelectionChanged="ddlCategory_SelectionChanged"  />

Upvotes: 3

Related Questions