Hello,
I am using the XamRichTextEditor control and I'm trying to figure out how I can change the default values for the font name and size.
I am NOT interested when loading content into the editor. I am interested when the end user starts typing in the editor when the editor is completely empty/blank.
The initial font size is 11 and the font name is null but it's themed "Minor".
I've already tried changing the DefaultCHaracterSettings property on the RootNode object, but that doesn't actually work. I've also tried changing the character settings on the first ParagraphNode created by the editor by default, but that only temporarily fixes it. I am assuming that those font name/size initial values come from somewhere in the editor object and I want to know where so I can overwrite them.
Any ideas?
Hello Corneliu,
I am glad that I was able to assist you on this matter and I believe the topics discussed here will help other community members as well.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Andrew,
You're right, it's the same behavior as in MS Word. Basically yes, I have 2 dropdowns for font name and font size and I was changing those properties this way.Thanks for your help with this! You've been more than helpful.
I believe the behavior is expected, but would it be possible for you to provide some more detail or modify the original sample I had sent you to demonstrate when you are setting the XamRichTextEditor.Selection.ApplyFontSize(36)? Are you doing this in a button click, or something of the like?
I had modified my original sample to do this on a Button click, and I am seeing the same behavior as what Microsoft Word does. For example, if you open a word document and type a few characters and then change the font size, you will notice that the caret does not change its size until you type the next character. The same remains true for the XamRichTextEditor, in this case.
Please let me know if you have any other questions or concerns on this matter.
Hello Andrew,
Your sample solution and detailed answer solved my problem so thank you for that.
Though while testing I came across another issue. It's related to this topic but it's not the same. I can create another post if you think that's best. Until then I'll just post the scenario
Scenario:Using your sample, after typing some content (using the same font name/size), I am trying to change the font size to "36" for all the text that follows. I am using Selection.ApplyFontSize(36). Notice that the keyboard cursor's height is the same with the previous font size (18), not the new one (36). Once I type something, the keyboard cursor will change its height to the current font size (36). The content font size is right, but the cursor is not right prior to typing.
Am I applying the font size properly using the selection property? do I need to do something extra so the cursor also changes its height?
Thanks!
Thank you for your post!
To change the initial font settings of the XamRichTextEditor, you will need to set the character settings on the XamRichTextEditor.Document. You can do this by using the ApplyCharacterSettings method on the RichTextDocument object that represents this document. That method will take a DocumentSpan as its first parameter. Since it is the initial load of the XamRichTextEditor, I would recommend setting that to DocumentSpan.All. The next parameter is your CharacterSettings object, and finally it takes an out string error, in case something goes wrong.
Regarding the font family query, each CharacterSettings object has a FontSettings property. This takes a FontSettings object, which has Ascii, ComplexScript, EastAsia, and HighAnsi properties for their different corresponding script characters. In your corresponding property, you will want to place the string name of the font family that you wish to apply. Most commonly, you will likely be using the Ascii property for the English language.
I have attached a sample project to demonstrate the above. I hope this helps you.