Problem using RadRichTextBox with RadRibbox toolbar

1 Answer 236 Views
RichTextBox
alex
Top achievements
Rank 2
Bronze
Iron
Iron
alex asked on 24 Oct 2022, 05:58 AM | edited on 24 Oct 2022, 06:00 AM

Hey,

I downloaded the demo code and created a control called "RadRichTextBoxToolBarControl". This control contains many controls:  RadRibbonComboBox to change font Family and Size, FormattingColorPicker to change text color, etc.

The DataContext of the control is RadRichTextBox, Path=Commands.

This way allowed to have all the functionality with zero code behind.

The RichTextBox gets the style according to the RadRichTextBoxToolBarControl as expected.

The problem is that after I wrote some text and change the text style (font family, size, color) then I should click the end of the line to have the focus on the RichTextBox and start typing.

The problem is that the new text uses the style of the text to the left of the cursor instead of the styling configured in the toolbar. 
I would like to have the same behavior as word. While typing or selecting text, the style should be inherited from the toolbar options.

Unfortunately, I can't share my code but I think that the explanation is enough.

1 Answer, 1 is accepted

Sort by
0
Vladislav
Telerik team
answered on 26 Oct 2022, 03:42 PM

Hi Alex,

If I understand you correctly, you have successfully plugged in most of the RichTextBox's commands, and you struggle with the ones mentioned (ChangeFontFamilyCommand, ChangeFontSizeCommand, etc.). What these commands have in common is that they depend on a command parameter, and if it is missing, the command will not execute. I would suggest checking again if the command parameter is passed properly. Note that the ChangeFontSizeCommand expects its parameter to be of type DIP, and the user interface should show it in Points, so you will need to use a custom converter that uses the Unit.PointToDip() method. You can skip the conversion if you use the workaround demonstrated in the Telerik Editor example - populating the items with Tag that represents the size in DIP and passing it to the command.

You can check if the command bindings are properly set, by subscribing to the CommandExecuting and CommandExecuted events of the RichTextBox.

If you still struggle after that you can prepare a small sample project and share it. This way we can better acknowledge what is wrong with the approach and help you fix it.

Regards,
Vladislav
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 27 Oct 2022, 01:34 PM | edited

Hello Vladislav,

Thank you for your fast reply.

I don't have any issue with the commands.

When I select some text and change the font color, it works as expected.

The problem is the following:

1. Write some text.

2. Choose another font color (for exmple: red).

3. Click the end of the line to start typing.

4. The font color changes automatically to the default text color (for example: black).

The question is why the font color or size is changing without click on the corresponding control? and how can I prevent it?

Vladislav
Telerik team
commented on 01 Nov 2022, 07:46 AM

Hi Alex,

To tell you what is wrong, I will need a sample demo. It doesn't need to be your production-ready project, just a new sample with the RichTextBox, the control used for the ribbon, and at least one of the controls that fail to execute correctly. Without it, we can only guess what might be wrong with the implementation.

Looking forward to your reply.

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 23 Nov 2022, 06:17 PM | edited

Hello Validslav.

Unfortunetaly I can't upload the code from my project. The issue is not related to my control because if I select some part of the text and then change the color, style, font: it works as expected. The problem is that I am not able to choose a style when the text is not selected, because when I go back to the RichTextBox (after changing the style in the tool bar) and it is get focused, the font style while writing is the same font of the text instead of the toolbae style. In word for example,  after changing a stytle from toolbar, the focus is back automaticlly to the text so the style of the toolbar is applied. 

Can you share me sone example code with that correct behavior?

Vladislav
Telerik team
commented on 28 Nov 2022, 07:05 AM

Hi Alex,

I have created a small sample project demonstrating the Custom Ribbon for the RichTextBox and everything seems to work as intended. You can check the demo and the recording.

I hope you will find this information helpful.

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 28 Nov 2022, 07:11 PM | edited

Thank you for your effort. I appreciate it!

I can see that the behavior is the same as yours if I first click on the text (put the focus and cursor on the RichTextBox).

In case that:

1. The focus is on the TextBox

2. Select the new style

3. The focus is still the TextBox so I can write with the new settings.

 

In case that:

1. I open the window

2. I Didn't put the focus on the text

3. First click is on the toolbar setting

4. Then if I click the text

5. When the focus is back, the style is the current and not the new one.

Comparing to word, it is not happening because when I open a new document the focus is on the text (if exist).
How can I automatically get the focus on the RichTextBox when I enter edit mode (enable the RichTextBox control).

Vladislav
Telerik team
commented on 30 Nov 2022, 12:39 PM

I have tried to mimic the described behavior by adding a text box inside the ribbon which get the focus prior to changing the font. After I change the font, the focus is back to the actual RichTextBox, as the commands automatically call the focus on their owner (the RIchTextBox). If you do not see this behavior on your side, you might be doing something wrong, and I will need a sample project to reproduce it, in order to help you.

As for focusing on the control at the start of the program, you can force it if you call the Focus() method on the RichTextBox.

I hope this helps.

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 30 Nov 2022, 05:19 PM

Can you please share your xaml?

I put both controls on a grid, maybe the owner is different

Vladislav
Telerik team
commented on 01 Dec 2022, 05:49 AM

You can find the xaml in one of my previous comments. What I did was add another textbox control inside the ribbon as seen in the screenshot.
Tags
RichTextBox
Asked by
alex
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Vladislav
Telerik team
Share this question
or