/// <summary> /// Processes the dragging of the RichTextFormatBar /// </summary> private void ProcessMove(DragDeltaEventArgs e) { AdornerLayer layer = AdornerLayer.GetAdornerLayer(Target); UIElementAdorner <Control> adorner = layer.GetAdorners(Target)[0] as UIElementAdorner <Control>; adorner.SetOffsets(adorner.OffsetLeft + e.HorizontalChange, adorner.OffsetTop + e.VerticalChange); }
/// <summary> /// Positions the FormatBar so that is does not go outside the bounds of the RichTextBox or covers the selected text /// </summary> /// <param name="adorningEditor"></param> private void PositionFormatBar(Control adorningEditor) { Point mousePosition = Mouse.GetPosition(_richTextBox); double left = mousePosition.X; double top = (mousePosition.Y - 15) - adorningEditor.ActualHeight; //top if (top < 0) { top = mousePosition.Y + 10; } //right boundary if (left + adorningEditor.ActualWidth > _richTextBox.ActualWidth - 20) { left = left - (adorningEditor.ActualWidth - (_richTextBox.ActualWidth - left)); } _adorner.SetOffsets(left, top); }