I've been researching this for a while and to no avail (I've tried to get command working but there is somethign I'm seriously missing I think. Very new to WPF's way of doing things which isn't helping (but really liking what I find with WPF)
I'm have the same issue as this post: Get the ListBox row object from a button that is on the DataTemplate
I have a listbox with labels + 2 buttons in each datatemplate. I need t know which row is being clicked when the button is clicked. (The row is not selected at all so Selectedindex is out the question). I really like Vaccano's method but can't seem to get it to work on the informatin he has given (he states himself it is very brief)
<ListBox x:Name="lbDirectoryTreeBox" Height="auto" Width="auto" Grid.Column="0" Grid.Row="0" Margin="10,10,5,10" ItemsSource="{Binding}"
MouseDoubleClick="lbDirectoryBox_MouseDoubleClick" SelectionChanged="lbDirectoryTreeBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnOpenFolder" Content="R" Width="20" Height="20" Click="btnDirectoryOpen_Click" />
<Button x:Name="btnAddFolder" Content="R" Width="20" Height="20" Click="btnAddFolder_Click" />
<Label Width="auto" Content="{Binding Path=Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How can I get the selectedindex of the row after clicking either of the buttons? (in c#)
Thanks in advance for any help here.