728x90
반응형
728x170

WebView2 에 html source 처리하는 방법입니다.

using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows;

using Microsoft.Win32;

using Path = System.IO.Path;

namespace Wpf.WebView2Test
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            BindingHtml();
        }

        private async void BindingHtml()
        {
            string html = "<body><h1>Hello World</h1></body>";
            await webView2.EnsureCoreWebView2Async();

            webView2.NavigateToString(html);
        }
    }
}

반드시 EnsureCoreWebView2Async() 를 호출해야합니다.

실행결과

[Source]
https://github.com/kei-soft/KJunBlog/tree/master/Wpf.WebView2Test

728x90
반응형
그리드형
Posted by kjun

댓글을 달아 주세요