Browse Source

RichTextBox: placed the UpdateText method on a background thread using the dispatcher to asyncronously update the text property. This dramatically improves performance.

import/raw
brianlagunas_cp 16 years ago
parent
commit
1044f95353
  1. 17
      Main/Source/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBox/RichTextBox.cs

17
Main/Source/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/RichTextBox/RichTextBox.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Threading;
namespace Microsoft.Windows.Controls namespace Microsoft.Windows.Controls
{ {
@ -9,6 +10,7 @@ namespace Microsoft.Windows.Controls
#region Private Members #region Private Members
private bool _textHasLoaded; private bool _textHasLoaded;
bool isInvokePending;
#endregion //Private Members #endregion //Private Members
@ -80,6 +82,15 @@ namespace Microsoft.Windows.Controls
#region Methods #region Methods
private void InvokeUpdateText()
{
if (!isInvokePending)
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(UpdateText));
isInvokePending = true;
}
}
private void UpdateText() private void UpdateText()
{ {
//when the Text is null and the Text hasn't been loaded, it indicates that the OnTextPropertyChanged event hasn't exceuted //when the Text is null and the Text hasn't been loaded, it indicates that the OnTextPropertyChanged event hasn't exceuted
@ -90,6 +101,8 @@ namespace Microsoft.Windows.Controls
if (_textHasLoaded) if (_textHasLoaded)
Text = TextFormatter.GetText(Document); Text = TextFormatter.GetText(Document);
isInvokePending = false;
} }
#endregion //Methods #endregion //Methods
@ -102,11 +115,11 @@ namespace Microsoft.Windows.Controls
if (binding.UpdateSourceTrigger == UpdateSourceTrigger.Default || binding.UpdateSourceTrigger == UpdateSourceTrigger.LostFocus) if (binding.UpdateSourceTrigger == UpdateSourceTrigger.Default || binding.UpdateSourceTrigger == UpdateSourceTrigger.LostFocus)
{ {
LostFocus += (o, ea) => UpdateText(); LostFocus += (o, ea) => InvokeUpdateText();
} }
else else
{ {
TextChanged += (o, ea) => UpdateText(); TextChanged += (o, ea) => InvokeUpdateText();
} }
} }

Loading…
Cancel
Save