csharp get value datatemplate element
- by To-me
Hello,
Here is my code
<ListBox x:Name="myList" IsSynchronizedWithCurrentItem="True" SelectionChanged="editElement">
<ListBox.ItemTemplate>
<DataTemplate x:Name="ElementItemTemplate">
<StackPanel Name="stackPanelElementItem" Orientation="Horizontal">
<Label Name="SelectedItemlabel" Content="{Binding}" />
<Button Name="buttonDelElement" Click="btnDelElement">Delete</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
private void btnDelElement(object sender, RoutedEventArgs e)
{
ListBoxItem lbi2 = (ListBoxItem)(lstCursus.ItemContainerGenerator.ContainerFromItem(myList.Items.CurrentItem));
String selectedItem = lbi2.Content.ToString();
MessageBox.Show("Selected Item " + selectedItem + " .");
private void editCursus(object sender, RoutedEventArgs e)
{
MessageBox.Show("Selected Item " + selectedItem + " .");
/* some code to edit selected item using linq */
}
My issue, SelectionChange doesn't work anymore and when I click on buttonDelElement, Selected Item doesn't change immediately.
Please, any ideas?