How to get and set value of Monaco editor inside a WPF application

Aidan Kinzie 66 Reputation points
2022-07-29T03:01:51.317+00:00

How do I take Monaco editor text, and use it in the C# application as a string?

Developer technologies | Windows Presentation Foundation
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Reza Aghaei 4,996 Reputation points Volunteer Moderator
    2022-07-29T15:52:03.443+00:00

    Assuming you have already followed the instructions to How to use Monaco editor in a WPF application, then you can use javascript editor.GetValue and editor.setValue functions to work with the editor.

    For example, to get the value of the editor:

    var value = await webView21.ExecuteScriptAsync("editor.getValue();");  
    MessageBox.Show(value);  
    

    Or to set the value of the editor:

    await webView21.ExecuteScriptAsync("editor.setValue('Hi!');");  
    

    Note:

    226226-image.png

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.