void TextEditorMouseHover(object sender, MouseEventArgs e) { Debug.Assert(sender == this); ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.Adapter); var pos = GetPositionFromPoint(e.GetPosition(this)); args.InDocument = pos.HasValue; if (pos.HasValue) { args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value); } TextMarkerService textMarkerService = this.Adapter.GetService(typeof(ITextMarkerService)) as TextMarkerService; if (args.InDocument && textMarkerService != null) { var markersAtOffset = textMarkerService.GetMarkersAtOffset(args.Editor.Document.PositionToOffset(args.LogicalPosition.Line, args.LogicalPosition.Column)); ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null); if (markerWithToolTip != null) { args.SetToolTip(markerWithToolTip.ToolTip); } } if (!args.Handled) { // if request wasn't handled by a marker, pass it to the ToolTipRequestService ToolTipRequestService.RequestToolTip(args); } if (args.ContentToShow != null) { var contentToShowITooltip = args.ContentToShow as ITooltip; if (contentToShowITooltip != null && contentToShowITooltip.ShowAsPopup) { if (!(args.ContentToShow is UIElement)) { throw new NotSupportedException("Content to show in Popup must be UIElement: " + args.ContentToShow); } if (popup == null) { popup = CreatePopup(); } if (TryCloseExistingPopup(false)) { // when popup content decides to close, close the popup contentToShowITooltip.Closed += (closedSender, closedArgs) => { popup.IsOpen = false; }; popup.Child = (UIElement)args.ContentToShow; //ICSharpCode.SharpDevelop.Debugging.DebuggerService.CurrentDebugger.IsProcessRunningChanged SetPopupPosition(popup, e); popup.IsOpen = true; } e.Handled = true; } else { if (toolTip == null) { toolTip = new ToolTip(); toolTip.Closed += ToolTipClosed; } toolTip.PlacementTarget = this; // required for property inheritance if (args.ContentToShow is string) { toolTip.Content = new TextBlock { Text = args.ContentToShow as string, TextWrapping = TextWrapping.Wrap }; } else { toolTip.Content = args.ContentToShow; } toolTip.IsOpen = true; e.Handled = true; } } else { // close popup if mouse hovered over empty area if (popup != null) { e.Handled = true; } TryCloseExistingPopup(false); } }