Доступ к TabControl из ContextMenu TabItem - PullRequest
0 голосов
/ 23 сентября 2019

Количество строк в WPF dataGrid синхронизировано с количеством TabItems в TabControl.Пожалуйста, см. Изображение UI ScreenShot.Теперь, когда я нажимаю на Удаление строки в contextMenu из DataGrid .ie, TabItem также должен быть удален.Чтобы выполнить эту операцию, я хочу перейти к определенному Tab-Control в Code и удалить TabItem, который синхронизирован с DataGridRow.

Пока я могу удалить строку в DataGrid, но не могу удалить конкретныйTabItem из TabControl.

        //Code to Delete the DataGridRow from DataGrid Collection
        //Get the clicked MenuItem
        var menuItem = (MenuItem)sender;
        //Get the ContextMenu to which the menuItem belongs
        var contextMenu = (ContextMenu)menuItem.Parent;
        //Find the placementTarget
        var item = (DataGridRow)contextMenu.PlacementTarget;
        //Get the underlying item, that you cast to your object that is bound
        //to the DataGrid (and has subject and state as property)
        var toDeleteFromBindedList = item.DataContext as IndHazardViewModel;
        DataContextHARAFunVM.HazardsCollection.Remove(toDeleteFromBindedList);
    //Draft Code to Delete particular TabItem from tabControl
    var target = (FrameworkElement)sender;
    while (target is ContextMenu == false)
           target = (FrameworkElement)target.Parent;
    var tabItem = (target as ContextMenu).PlacementTarget;

Мне нужна помощь с кодом для перехода из ContextMenu в TabControl.

...