From 03aa223ff79a3d4490670c862fcb64d61f85fc30 Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Sun, 31 Oct 2010 04:22:56 +0000 Subject: [PATCH] RichTextBox: changed format bar to only show when highlighting with mouse at the end of the selection, not during selection. try to improve hiding the format bar when mousing outside of the richtextbox. --- .../RichTextBoxFormatBarManager.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs index 18ec1824..3a0fd2d9 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using Microsoft.Windows.Controls.Core; +using System.Windows.Input; namespace Microsoft.Windows.Controls { @@ -51,10 +52,10 @@ namespace Microsoft.Windows.Controls #region Event Handlers - void RichTextBox_SelectionChanged(object sender, EventArgs e) + void RichTextBox_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TextRange selectedText = new TextRange(_richTextBox.Selection.Start, _richTextBox.Selection.End); - if (selectedText.Text.Length > 0 && !String.IsNullOrWhiteSpace(selectedText.Text)) + if (selectedText.Text.Length > 0 && !String.IsNullOrWhiteSpace(selectedText.Text)) { ShowAdorner(); } @@ -64,6 +65,16 @@ namespace Microsoft.Windows.Controls } } + void RichTextBox_PreviewMouseMove(object sender, MouseEventArgs e) + { + //if the mouse moves outside the richtextbox bounds hide the adorner + //though this deosn't always work, especially if the user moves the mouse very quickly. + //need to find a better solution, but this will work for now. + Point p = e.GetPosition(_richTextBox); + if (p.X <= 5.0 || p.X >= _richTextBox.ActualWidth - 5 || p.Y <= 3.0 || p.Y >= _richTextBox.ActualHeight - 3) + HideAdorner(); + } + #endregion //Event Handlers #region Methods @@ -77,23 +88,12 @@ namespace Microsoft.Windows.Controls { _richTextBox = richTextBox; _richTextBox.PreviewMouseMove += RichTextBox_PreviewMouseMove; - _richTextBox.Selection.Changed += RichTextBox_SelectionChanged; + _richTextBox.PreviewMouseLeftButtonUp += RichTextBox_PreviewMouseLeftButtonUp; _adorner = new UIElementAdorner(_richTextBox); formatBar.RichTextBox = _richTextBox; - _toolbar = formatBar; - - } - - void RichTextBox_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e) - { - //if the mouse moves outside the richtextbox bounds hide the adorner - //though this deosn't always work, especially if the user moves the mouse very quickly. - //need to find a better solution, but this will work for now. - Point p = e.GetPosition(_richTextBox); - if (p.X <= 5.0 || p.X >= _richTextBox.ActualWidth - 5 || p.Y <= 3.0 || p.Y >= _richTextBox.ActualHeight - 3) - HideAdorner(); + _toolbar = formatBar; } ///