It's easy to bind something to the SelectedIndex of the ListBox, but I want every item in the ListBox be able to bind to it's index in the list.
Might sound weird, so here's what I'm trying to do:
<DataTemplate x:Key="ScenarioItemTemplate">
<Border
Margin="8,2,8,2"
Background="#FF3C3B3B"
BorderBrush="#FF797878"
BorderThickness="2"
CornerRadius="5">
<DockPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,2,0,0">
<Label HorizontalAlignment="Left"
DockPanel.Dock="Left"
FontWeight="Heavy"
Foreground="White"
Content="{Binding Path=Position}"
MinWidth="50"/>
<Label
Content="{Binding Path=Name}"
DockPanel.Dock="Left"
FontWeight="Heavy"
Foreground="white"/>
<Label
Content="{Binding Path=Header}"
Foreground="white"
DockPanel.Dock="Left"/>
<TextBlock HorizontalAlignment="Right"
Background="#FF3C3B3B"
DockPanel.Dock="Left" Foreground="White" FontWeight="Heavy">
<Hyperlink Click="CloseHyperlink_Click" Tag="">X</Hyperlink>
</TextBlock>
I want to bind the TAG property of the hyperlink to the index of the item in question. So that when the user clicks the hyperlink, I can determine what item caused the event using the TAG property of that hyperlink.
var hyperlink = (Hyperlink)sender;
var index = Convert.ToInt32(hyperlink.Tag);
Suggestions?