@ -52,17 +52,22 @@ namespace Microsoft.Windows.Controls
#region Event Handlers
void RichTextBox_Preview MouseLeft ButtonUp ( object sender , MouseButtonEventArgs e )
void RichTextBox_MouseButtonUp ( object sender , MouseButtonEventArgs e )
{
TextRange selectedText = new TextRange ( _ richTextBox . Selection . Start , _ richTextBox . Selection . End ) ;
if ( selectedText . Text . Length > 0 & & ! String . IsNullOrWhiteSpace ( selectedText . Text ) )
if ( e . LeftButton = = MouseButtonState . Released )
{
ShowAdorner ( ) ;
}
else
{
HideAdorner ( ) ;
TextRange selectedText = new TextRange ( _ richTextBox . Selection . Start , _ richTextBox . Selection . End ) ;
if ( selectedText . Text . Length > 0 & & ! String . IsNullOrWhiteSpace ( selectedText . Text ) )
{
ShowAdorner ( ) ;
}
else
{
HideAdorner ( ) ;
}
}
e . Handled = true ;
}
void RichTextBox_PreviewMouseMove ( object sender , MouseEventArgs e )
@ -96,7 +101,10 @@ namespace Microsoft.Windows.Controls
{
_ richTextBox = richTextBox ;
_ richTextBox . PreviewMouseMove + = RichTextBox_PreviewMouseMove ;
_ richTextBox . PreviewMouseLeftButtonUp + = RichTextBox_PreviewMouseLeftButtonUp ;
//we cannot use the PreviewMouseLeftButtonUp event because of selection bugs.
//we cannot use the MouseLeftButtonUp event because it is handled by the RichTextBox and does not bubble up to here, so we must
//add a hander to the MouseUpEvent using the Addhandler syntax, and specify to listen for handled events too.
_ richTextBox . AddHandler ( Mouse . MouseUpEvent , new MouseButtonEventHandler ( RichTextBox_MouseButtonUp ) , true ) ;
_ richTextBox . TextChanged + = RichTextBox_TextChanged ;
_ adorner = new UIElementAdorner < Control > ( _ richTextBox ) ;