Look, I did it, but I KNOW this is wrong:
After you enable the work item using code to the question:
IPendingChangesExt pendingChangesExt = ParentSection.GetService<IPendingChangesExt>(); var workItemSection = pendingChangesExt.GetType().GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var modelType = workItemSection.FieldType; var model = workItemSection.GetValue(pendingChangesExt); var m = modelType.GetMethod("AddWorkItemById", BindingFlags.NonPublic | BindingFlags.Instance); m.Invoke(model, new object[] { selectedWorkItemId });
I added a few new codes (these are different functions, okay?) ... this second call will wait until the work item appears in the "Related work items of pending changes" section and changes its link to Resolve link manually.
IPendingChangesExt pendingChangesExt = ParentSection.GetService<IPendingChangesExt>(); var model = pendingChangesExt .GetType() .GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var modelType = model.FieldType; var workItemSection = model.GetValue(pendingChangesExt); var selectedWil = workItemSection .GetType() .GetProperty("SelectedWorkItems") .GetValue(workItemSection) as ObservableCollection<WorkItemValueProvider>; var availablWil = workItemSection .GetType() .GetProperty("WorkItemsListProvider") .GetValue(workItemSection) as WorkItemsListProvider; // Waiting for section to be ready to start association while (!availablWil.WorkItems.Where(x => x.Id == selectedWorkItemId).Any()) { await System.Threading.Tasks.Task.Delay(25); } selectedWil.Clear(); selectedWil.Add(availablWil.WorkItems.Where(x => x.Id == selectedWorkItemId).First()); EnvDTE80.DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2; dte2.ExecuteCommand("TeamFoundationContextMenus.WorkItemActionLink.TfsContextPendingChangesPageWorkItemActionLinkAssociate"); selectedWil.Clear();
Despite the effectiveness of this code, I am still working on a better solution when running the second method. The default value suggested in the comments will not work, because the developer should be able to bind / allow only when the button is selected.
source share