Hi I have had an error for a long time with the richtextbox.selection.applypropertyvalue()
function where it wont work the first time I apply it (click the button) to the richtextbox it just wont do so (I have attached a image .gif below which shows the problem much more in depth)
Here is the code for when I click the button, it is the same for each button / combobox that is on the tab bar
CODE:
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);
}
}
}
image:
Description Of Image: this image is showing that I have to enter text first before I can set the text property on the end of the text. But if I try to do so by clicking the button I once again have to enter text and then again press the button (described in photo)
just a note the MessageBox is just a test that checks selection length (Not the error)