Beispiel #1
0
        public static async Task AssemblyInitialize(TestContext context)
        {
            var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

            windowTask = Helpers.RunSTATask(() =>
            {
                application = new Application();
                mainWindow  = application.MainWindow = new System.Windows.Window
                {
                    WindowStartupLocation = WindowStartupLocation.CenterScreen,
                    Width  = 400,
                    Height = 300,
                };
                mainWindow.Loaded += async(s, e) =>
                {
                    wpfSyncContext     = SynchronizationContext.Current !;
                    webView            = new WebView2();
                    mainWindow.Content = webView;
                    await webView.EnsureCoreWebView2Async();
                    await WebView2DOM.InitAsync(webView);
                    void DOMContentLoaded(object?s, EventArgs e)
                    {
                        webView.DOMContentLoaded().Handler -= DOMContentLoaded;
                        tcs.SetResult();
                    }
                    webView.DOMContentLoaded().Handler += DOMContentLoaded;
                    webView.NavigateToString("<html></html>");
                };
                mainWindow.Show();
                application.Run();
            });
            await tcs.Task;
        }
Beispiel #2
0
        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            await webView.EnsureCoreWebView2Async();

            await WebView2DOM.InitAsync(webView);

            webView.CoreWebView2.DOMContentLoaded += async(s, e) =>
            {
                await webView.InvokeInBrowserContextAsync(DOMContentLoaded);
            };
            webView.NavigateToString(@"
				<h1>Welcome to C# DOM</h1>
				<p>The current time is <span id='current-time'></span></p>
				<p>requestAnimationFrame FPS (called from C#) is <span id='fps'></span></p>
				<p>
					<button id='jsAlertButton'>(JS) Show alert</button>
					<br />
					<button id='csAlertButton'>(C#) Change window size</button>
				</p>
			"            );
        }