@ -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 , MouseButton EventArgs 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 < Control > ( _ 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 ;
}
/// <summary>