public MainWindow()
        {
            InitializeComponent();

            JsInterop = new JavaScriptInterop(webView);
            Interop   = new DotnetInterop(this, JsInterop);

            // renders in a generic background color - so hide it
            webView.Visibility = Visibility.Hidden;

            DataContext = Model;
            Loaded     += MainWindow_Loaded;

            InitializeAsync();


            webView.NavigationCompleted += WebView_NavigationCompleted;
            webView.Unloaded            += (s, a) => webView.Visibility = Visibility.Hidden;
            webView.ContentLoading      += WebView_ContentLoading;

            // Using a file URL
            //webView.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "Editor/editor.htm"));

            // Using a Mapped virtual url set with CoreWebView2.SetVirtualHostNameToFolderMapping
            webView.Source = new Uri("https://test.editor/editor.htm");
        }
        private async void SetContent_Click(object sender, RoutedEventArgs e)
        {
            var markdown = @"# New Markdown text

This text is inserted from .NET into this document.
and this is **bold**.

Quotes: double - "" and single '

* Line 1
* Line 2    
";


            var cmd = "textEditor.setvalue(" + JsonSerializationUtils.Serialize(markdown) + ")";

            webView.CoreWebView2.ExecuteScriptAsync(cmd);
            return;

            //webView.CoreWebView2.ExecuteScriptAsync("textEditor.setvalue('# Hello World')");

            var jsInterop = new JavaScriptInterop(webView);
            await jsInterop.CallMethod("setvalue", markdown);

            //jsInterop.CallMethod("openSearchAndReplace", "dead", "wet");

            await jsInterop.CallMethod("setCursorPosition", 3, 22);

            await Task.Delay(3000);

            await jsInterop.CallMethod("setselection", "-- inserted from .NET at " + DateTime.Now.ToString("t") + " -- ");
        }
Exemplo n.º 3
0
 public DotnetInterop(MainWindow mainWindow, JavaScriptInterop jsInterop)
 {
     JsInterop = jsInterop;
     Window    = mainWindow;
 }