In WPF programming, I have a problem to write the button click event handler. Because the button is inside a listbox item(a part of datatemplate), and when the button is cli
ListBox.selectedItem and listbox.SelectedIndex will be set as part of clicking the button.
Assuming the items in the list box are say type MyListBoxItem
void SomeButtonClick(Object sender, EventArgs e)
{
ListBox lb = sender as ListBox
if (lb != null)
{
MyListBoxItem item = lb.SelectedItem As MyListBoxItem;
if (item != Null)
{
item.MethodRelatedToButton(); // maybe
}
}
}
Amplified as requested