private void ContextMenuCommand_Execute(object sender, EventArgs args) { ThreadHelper.ThrowIfNotOnUIThread(); var command = (OleMenuCommand)sender; var isRoot = command.MatchedCommandId == 0; var index = isRoot ? 0 : command.MatchedCommandId - CommandId_ContextMenuStart; var attribute = CurrentNode.Attributes[index]; if (attribute.IsChecked) { TryApplyChanges(CurrentNode.Remove(attribute)); } else { TryApplyChanges(CurrentNode.Add(attribute, out var textSpan)); if (textSpan.HasValue) #pragma warning disable VSTHRD001 // Avoid legacy thread switching APIs { Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { NavigateToSource(textSpan.Value); EnsureDocumentActivated(); })); } #pragma warning restore VSTHRD001 // Avoid legacy thread switching APIs } NavigatableMarker = CurrentNode.CreateMarker(navigationSuggested: false); }