This is a migrated thread and some comments may be shown as answers.

Call a RichTextBox command from code behind

3 Answers 190 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Patrick asked on 11 Apr 2012, 10:48 PM
Hi,

I'm looking for a way to call the save command from code behind. I tried different kinds of maner but with no success.

Thanks

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 12 Apr 2012, 01:23 PM
Hello Patrick,

You need to call Execute method of the SaveCommand property as in this line of code:

this.radRichTextBox.Commands.SaveCommand.Execute();

For more detailed information, please refer to this help article where you can find list of all commands exposed by RadRichTextBox and examples for their using with UI elements. You can also take a look at the Import/Export article which contains snippets of how you can save the document to a stream (which can happen without using the open and save file dialogs.

I hope this helps. Don't hesitate to contact us if you have other questions.

All the best,
Vasil
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Patrick
Top achievements
Rank 2
answered on 12 Apr 2012, 01:54 PM
Thanks Vasil. I had finally found my bug. I called properly the save command but it was in the context where, if the user want to quit the application and the document need to be saved, I ask to save the document. Right after the save command, I call the End command for stopping the application. So, the command was executed but it isn't in a modal form and the End command arrive before the window shown. Now, my new question is, how can we call a command and continue only after the end of that command?

Here is my code:

 

 

 

 

Private Sub MnuQuit_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles MnuQuit.Click
    If bNeedToBeSaved Then
        If MsgBox("Do you want to save the file?", vbYesNo + vbQuestion, "The document need to be saved") = vbYes Then
            editor.Commands.SaveCommand.Execute() 'I want to continue only when the save command is done.
        End If
    End If
  
    End
  
End Sub

 


Thanks a lot,

Patrick

0
Accepted
Vasil
Telerik team
answered on 17 Apr 2012, 02:52 PM
Hi Patrick,

Currently, the work in Save and Print is executed asynchronously using Dispatcher.BeginInvoke(). This was part of a workaround for a legacy issue related to ApplicationMenu in RadRibbonView. We will remove it and the fix will be included in the Latest Internal Build (expected next week), so you will be able to continue working with your application then. Unfortunately there is no good workaround with the current version.
After upgrade, you will be able to listen to RadRichTextBox.CommandExecuted event and perform your logic there:

this.radRichTextBox.CommandExecuted += (s, a) =>
    {
        if (a.Command is SaveCommand)
        {
            // your logic here
        }
    };
or put your code directly after the editor.Commands.SaveCommand.Execute() call, depending on your requirements.
Please, excuse us for the inconvenience. We have added points to your account for the report. Don't hesitate to contact us if you have other questions.

Greetings,
Vasil
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Patrick
Top achievements
Rank 2
Answers by
Vasil
Telerik team
Patrick
Top achievements
Rank 2
Share this question
or