I have a ListBox where the number of items is added based on and integer property set by a user. The items are created from a ControlTemplate resource that which is comprised of a Label and a TextBox inside of a DockPanel. The label is not data bound but I would like for it to have somewhat dynamic content based on the (index + 1) of the listboxitem for which it is contained. My question/problem is that I want to be able update the content of the label for each listbox item, but cannot access the label for some reason. I am unaware of any way to do this through data-binding of the label since the label is in a template and has no knowledge that it has a parent that is a listbox item. Can anyone help me clear up some of these confusions to get me back on the right track, please?
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<DockPanel Background="Transparent" Height="28" Name="playerDockPanel" VerticalAlignment="Bottom">
<Label Name="playerNameLabel" DockPanel.Dock="Left" Content="Player"></Label>
<TextBox Height="23" Width ="150" Name="playerName" DockPanel.Dock="Right"/>
</DockPanel>
</ControlTemplate>
I would like to be able to bind the content of the label in xaml, or update the content of the label in the code behind. I'm not sure what the best route would be.