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. 26
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBoxFormatBar/RichTextBoxFormatBarManager.cs

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

@ -52,17 +52,22 @@ namespace Microsoft.Windows.Controls
#region Event Handlers #region Event Handlers
void RichTextBox_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) void RichTextBox_MouseButtonUp(object sender, MouseButtonEventArgs e)
{ {
TextRange selectedText = new TextRange(_richTextBox.Selection.Start, _richTextBox.Selection.End); if (e.LeftButton == MouseButtonState.Released)
if (selectedText.Text.Length > 0 && !String.IsNullOrWhiteSpace(selectedText.Text))
{ {
ShowAdorner(); TextRange selectedText = new TextRange(_richTextBox.Selection.Start, _richTextBox.Selection.End);
} if (selectedText.Text.Length > 0 && !String.IsNullOrWhiteSpace(selectedText.Text))
else {
{ ShowAdorner();
HideAdorner(); }
else
{
HideAdorner();
}
} }
e.Handled = true;
} }
void RichTextBox_PreviewMouseMove(object sender, MouseEventArgs e) void RichTextBox_PreviewMouseMove(object sender, MouseEventArgs e)
@ -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