【发布时间】:2014-07-05 13:58:10
【问题描述】:
您好,我的 richtextbox.selection.applypropertyvalue() 函数很长时间以来一直出错,当我第一次将它(单击按钮)应用到 Richtextbox 时它无法正常工作(我附上了一张图片 .gif下面更深入地显示了问题)
这是我单击按钮时的代码,标签栏上的每个按钮/组合框都是相同的
代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Windows.MessageBox.Show(textselectrangea.Text.Length.ToString());
if (textselectrangea.Text.Length != 0)
{
if (textselectrangea.GetPropertyValue(TextElement.FontWeightProperty).ToString() == "Normal" || textselectrangea.GetPropertyValue(TextElement.FontStyleProperty).ToString() == "{DependencyProperty.UnsetValue}")
{
boldbutton.FontWeight = FontWeights.Bold;
textselectrangea.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
}
else if (textselectrangea.GetPropertyValue(TextElement.FontWeightProperty).ToString() == "Bold")
{
boldbutton.FontWeight = FontWeights.Normal;
textselectrangea.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal);
}
}
//I think error occurs below here
else if (textselectrangea.Text.Length == 0)
{
if (richtextboxfile.Selection.GetPropertyValue(TextElement.FontWeightProperty).Equals(FontWeights.Normal))
{
boldbutton.FontWeight = FontWeights.Bold;
richtextboxfile.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
}
else if (richtextboxfile.Selection.GetPropertyValue(TextElement.FontWeightProperty).Equals(FontWeights.Bold))
{
boldbutton.FontWeight = FontWeights.Normal;
richtextboxfile.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal);
}
}
}
图片:
图片说明:此图片显示我必须先输入文本,然后才能在文本末尾设置 text 属性。但是,如果我尝试通过单击按钮来执行此操作,我必须再次输入文本,然后再次按下按钮(如图所示)
请注意,MessageBox 只是一个检查选择长度的测试(不是错误)
【问题讨论】:
-
使用调试器会发生什么?
-
调试器没有问题,同样的问题
-
@JohnSaunders 你认为这是 Visual Studio / C# 中的一个错误
-
我的意思是,当您单步执行时,您是否到达了您期望到达的所有行?顺便说一句,大多数人在他们的一生中都没有在 Visual Studio 中发现一个错误。他们在自己的代码中发现了更多错误。
-
是的,没有调试错误并且达到预期的行数
标签: c# wpf visual-studio select richtextbox