我的应用程序中有列表框。下面是屏幕截图。
当用户单击列表项时,我将显示详细页面。它正在处理以下选择更改的侦听器。
private void companiesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//get the selected item from list
Company selectedItem = (Company)e.AddedItems[0];
Uri uri = new Uri("/CompanyDetailsPage.xaml", UriKind.Relative);
//navigate to target page
this.NavigationService.Navigate(uri);
FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
root.DataContext = selectedItem;
}
}
到此为止还好。
现在,当用户单击该项目上的“删除”按钮时,我必须从列表中删除该项目。
private void Del_Btn_clicked(object sender, RoutedEventArgs e)
{
//get the Corresponding item from list i.e. On which delete button is placed.
//Delete saved company from the database
}
我无法获得放置删除按钮的特定列表项索引。何我能得到。
谢谢。