tags:

views:

44

answers:

1

I have a listbox that is bound to an observable collection of Audio (custom class). The Audio class has two properties, DisplayText (string) and a property called TarpIds (Observable Collection of Integer). I need to allow the user to change the TarpID in the combo box for each list item displayed and catch the selection change.

I created a DataTemplate that styles the DisplayText property from the Audio object and adds a ComboBox to display the available TarpIDs for this audio (These are dynamic and unique to each Audio). The DisplayText works great, but I can not get the TarpIDs to display in the ComboBox.

Here is what I have so far and thanks for any help. FYI I set the ItemSource at run time that binds the ListUploadAudio to the Observable Collection of Audio.

<Border BorderBrush="Red" Background="WhiteSmoke" CornerRadius="8">
                <Border.Resources>
                    <DataTemplate x:Key="UploadLayout" DataType="Audio">
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding Path=DisplayText}" 
                        FontWeight="Bold" Foreground="Blue">
                            </TextBlock>                                
                                <ComboBox x:Name="ListBoxTarpIDs"
                                         ItemsSource="{Binding Path=TarpIds}">                                        
                                </ComboBox>                                                                              
                           </StackPanel>
                    </DataTemplate>

                </Border.Resources>
                    <ListBox x:Name="ListUploadAudio" BorderBrush="Transparent" 
                         Background="Transparent" Width="230" Margin="10" 
                         Height="200" IsSynchronizedWithCurrentItem="True" SelectionMode="Multiple"
                         ItemTemplate="{DynamicResource UploadLayout}">
                </ListBox>
            </Border>
+1  A: 

Your ComboBox needs to bind SelectedValue as well as ItemsSource.

As far as your ComboBox not binding its items, your code looks right. I would suspect one of the following:

  • Misspelling (eg TarpIds vs TarpIDs)
  • Improperly defined setting (eg missing getter)
  • ListUploadAudio.ItemsSource not being set to expected value

If this doesn't work, I suggest you post your code, specifically the definition of your TarpIds property and the place where you set ListUploadAudio.ItemsSource

As a side note: You don't need the Path= in your bindings unless you are using namespaces.

Ray Burns
It was a cap issue.Thanks!