Browse Source

RichTextBoxFormatBar: fixed bug when you select text, then the format bar shows, then click the text again to unselect, the format bar still shows even though no text is selected.

pull/1645/head
brianlagunas_cp 16 years ago
parent
commit
ab899f8d9a
  1. 12
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs

12
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs

@ -52,7 +52,9 @@ namespace Microsoft.Windows.Controls
#region Event Handlers #region Event Handlers
void RichTextBox_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) void RichTextBox_MouseButtonUp(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Released)
{ {
TextRange selectedText = new TextRange(_richTextBox.Selection.Start, _richTextBox.Selection.End); 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))
@ -65,6 +67,9 @@ namespace Microsoft.Windows.Controls
} }
} }
e.Handled = true;
}
void RichTextBox_PreviewMouseMove(object sender, MouseEventArgs e) void RichTextBox_PreviewMouseMove(object sender, MouseEventArgs e)
{ {
//if the mouse moves outside the richtextbox bounds hide the adorner //if the mouse moves outside the richtextbox bounds hide the adorner
@ -96,7 +101,10 @@ namespace Microsoft.Windows.Controls
{ {
_richTextBox = richTextBox; _richTextBox = richTextBox;
_richTextBox.PreviewMouseMove += RichTextBox_PreviewMouseMove; _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; _richTextBox.TextChanged += RichTextBox_TextChanged;
_adorner = new UIElementAdorner<Control>(_richTextBox); _adorner = new UIElementAdorner<Control>(_richTextBox);

Loading…
Cancel
Save