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#
{count} votes

Accepted answer
  1. Reza Aghaei 4,986 Reputation points MVP 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 Answers by the question author, which helps users to know the answer solved the author's problem.