C# 在WPF richtextbox中更改fontsize后应用程序运行缓慢?
我正在使用WP richtextbox。我完成了从当前插入符号位置到下一行、上一行等的导航。它工作正常。我需要动态更改richtextbox中的fontsize 我使用以下方法更改字体大小:C# 在WPF richtextbox中更改fontsize后应用程序运行缓慢?,c#,wpf,performance,fonts,richtextbox,C#,Wpf,Performance,Fonts,Richtextbox,我正在使用WP richtextbox。我完成了从当前插入符号位置到下一行、上一行等的导航。它工作正常。我需要动态更改richtextbox中的fontsize 我使用以下方法更改字体大小: myrichtextbox.SetValue(TextElement.FontSizeProperty, fontSizedouble +10); myrichtextbox.FontSize = (txtAppendValue.FontSize + 10); 它可以工作。但在执行此方法后,其他功
myrichtextbox.SetValue(TextElement.FontSizeProperty, fontSizedouble +10);
myrichtextbox.FontSize = (txtAppendValue.FontSize + 10);
它可以工作。但在执行此方法后,其他功能的执行时间很长。在此之前,NavigateNextLine()
需要15毫秒到20毫秒。执行后需要40到50毫秒。我连续调用fontSize 4,5次,然后NavigateNextLine()
需要100毫秒到120毫秒
public void NavigateNextLine()
{
Int32 lineNumber;
txtAppendValue.CaretPosition.GetLineStartPosition(-int.MaxValue, out lineNumber);
Int32 iLineIndex = System.Math.Abs(lineNumber);
Int32 iCurrentStart = 0;
Int32 iCurWordLength = 0;
for (Int32 icnt = 0; icnt <= iLineIndex; icnt++)
{
m_strCurLineText = GetLineText(txtAppendValue.CaretPosition.GetLineStartPosition(lineNumber), 0, null);
iCurrentStart = iCurrentStart + m_strCurLineText.Length;
lineNumber += 1;
}
String[] strArr = m_strCurLineText.Split(' ');
if (strArr.Length > 0)
{
iCurWordLength = strArr[0].Length; // Get the first word length of current line
if (iCurWordLength == 0)
{
iCurWordLength = strArr[1].Length;
iCurrentStart = iCurrentStart + 1;
}
}
else
{
iCurWordLength = m_strCurLineText.Length; //to get single word line length
}
NewStart = iCurrentStart;
}
String GetLineText(TextPointer TextPointer, int LineRltv = 0, string Default = null)
{
TextPointer tp1 = TextPointer.GetLineStartPosition(LineRltv);
if (tp1 == null)
{
return Default;
}
else
{
tpNextLine2 = tp1.GetLineStartPosition(1);
TextRange tr = null;
if (tpNextLine2 == null)
{
tpNextLine2 = txtAppendValue.Document.ContentEnd;
}
tr = new TextRange(tp1, tpNextLine2);
return tr.Text;
}
}
public void NavigateNextLine()
{
Int32行号;
txtAppendValue.CaretPosition.GetLineStartPosition(-int.MaxValue,out lineNumber);
Int32 iLineIndex=System.Math.Abs(行号);
Int32 iCurrentStart=0;
Int32 iCurWordLength=0;
对于(Int32 icnt=0;icnt 0)
{
iCurWordLength=strArr[0].Length;//获取当前行的第一个字长
如果(iCurWordLength==0)
{
iCurWordLength=strArr[1]。长度;
iccurrentstart=iccurrentstart+1;
}
}
其他的
{
iCurWordLength=m_strurlinetext.Length;//获取单字行长度
}
NewStart=iccurrentstart;
}
字符串GetLineText(TextPointer TextPointer,int-LineRltv=0,字符串默认值=null)
{
TextPointer tp1=TextPointer.GetLineStartPosition(LineRltv);
if(tp1==null)
{
返回默认值;
}
其他的
{
tpNextLine2=tp1.GetLineStartPosition(1);
TextRange tr=null;
如果(tpNextLine2==null)
{
tpNextLine2=txtAppendValue.Document.ContentEnd;
}
tr=新的文本范围(tp1,tpNextLine2);
返回tr.Text;
}
}
那么问题是什么?如何解决
问候
阿琼两者都应该起作用:
txtAppendValue.ApplyPropertyValue(TextElement.FontSizeProperty, (double)10);
或
@Vivek:两者都应该有效。我的问题是在执行这一项后,另一项功能的执行速度变慢。我也尝试了这一项。@arjun ok找到了解决方案发布您的代码以获得其余功能@Muds:立即检查。
txtAppendValue.ApplyPropertyValue(TextElement.FontSizeProperty, 10.0)