Hello, I am currently trying to create some basic word processor features in a WPF project. I am using a RichTextBox and am aware of all of the EditingCommands (ToggleBold, ToggleItalic...ect.). The thing I am stuck on is allowing the user to change the fontsize and font face like in MS Office where the value changes for only the selected text and if there is no selected text then the value will change for the current caret position. I have come up with a decent amount of code to get this to work, but am having problems with the no selected text thing. Here is what I am doing for the RichTextBox.Selection.
TextSelection text = richTextBox.Selection;
if (text.IsEmpty)
{
//doing this will change the entire word that the current caret position
//is on which is not the desire/expected result.
text.ApplyPropertyValue(RichTextBox.FontSizeProperty, value);
}
else
//This works as expected.
text.ApplyPropertyValue(RichTextBox.FontSizeProperty, value);
So my question is how should I go about doing this? Is there a better/more convenient way to do this? One thought I had was that I would need to insert a new Inline into the Paragraph but I couldn't figure out how to do that. Any help is appreciated. Thank you.
Full disclaimer: This is an exact repost of this question from 7 months ago. I found it while searching for a solution to the exact same problem, however that question wasn't answered and I hope that someone will be able to answer it now nevertheless.