Hello.

There is a template in the listbox to display several fields of the table and there is a button to delete. I can associate it with a field from a table and at the same time find out the value of which button was pressed.

<telerik:RadListBox > <telerik:RadListBox.ItemTemplate > <DataTemplate> <Grid > <TextBlock Text="{Binding Path=Fio, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> <Label Content="{Binding Path=value2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> <Button Content="Х" Margin="5" HorizontalAlignment="Right" Tag="{Binding Path=Fio}" Click="ButtonDelete_Click" Name="ButtonDelete"/> </Grid> </DataTemplate> </telerik:RadListBox.ItemTemplate> </telerik:RadListBox> 

here is the button click handler:

 private void ButtonDelete_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; string Fio = (string)btn.Tag; MessageBox.Show(Fio); } 

at the same time I see, in front of which name the button was pressed.

And how do you know which account was pressed on the button, i.e. from which ListBoxItem this listbox.

    1 answer 1

    Decision:

    1. Call a ListBox somehow

    2. Zagindit Tag buttons on himself

    3. Take an item from the Tag in the handler and find its index from the Items collection

    4. (note that the common class containing the Tag property is FrameworkElement )

    5. (also for correct index search in this case it is required that the elements do not repeat (if they are not reference types). Otherwise, you need to read C # and turn on the brains;)


      <Button Tag="{Binding}" Click="ButtonDelete_Click" /> 

    -

     private void ButtonDelete_Click(object sender, RoutedEventArgs e) { object tag = (sender as FrameworkElement).Tag; int index = TelerikListBox.Items.IndexOf(tag); MessageBox.Show(index.ToString()); }