我有一个列表框,每一行都有一个删除按钮。当我点击删除按钮时,我需要获取列表框中被点击的行的索引以便删除这一行。怎么获取被点击项的索引?
以下是我的列表框:
<ListBox HorizontalAlignment="Left" Name="listBox1" Margin="-3,132,0,0" VerticalAlignment="Top" Width="498" SelectionChanged="listBox1_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0,1,0,0" BorderBrush="#FFC1BCBC" Width="490">
<Grid Height="70">
<Image Height="50"
HorizontalAlignment="Left"
Name="image"
Stretch="Fill"
VerticalAlignment="Top"
Width="50"
Source="{Binding iconPath}" Margin="8,8,0,0" />
<TextBlock Name="Name" Text="{Binding displayName}" VerticalAlignment="Center" Margin="60,0,0,0" Foreground="Black" FontWeight="SemiBold"></TextBlock>
<Button Name="btnDeleteRow" Width="50" Click="btnDeleteDashboard_Click" Margin="390,0,0,0" BorderBrush="Transparent" Style="{StaticResource logoutbtn_style}">
</Button>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>