How do you Bind to a ComboBox in a DataTemplate?
- by discwiz
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>