Пример #1
0
 private void OnClick_GoBack(object sender, RoutedEventArgs e)
 {
     if (_Browser.CanGoBack)
     {
         _Browser.Back();
     }
 }
Пример #2
0
        private void LoadBrowser()
        {
            var setting = new CefSharp.CefSettings();

            CefSharp.Cef.Initialize(setting);
            webView = new CefSharp.Wpf.ChromiumWebBrowser()
            {
                BrowserSettings =
                {
                    DefaultEncoding = "UTF-8"
                },
                JsDialogHandler = new BrowserDialog(),
                //MenuHandler = false,
            };
            webView.PreviewTextInput += (obj, args) =>
            {
                foreach (var character in args.Text)
                {
                    // 把每个字符向浏览器组件发送一遍
                    webView.GetBrowser().GetHost().SendKeyEvent((int)WM.CHAR, (int)character, 0);
                }

                // 不让cef自己处理
                args.Handled = true;
            };
            webView.PreviewKeyDown += (obj, args) =>
            {
                if (args.Key.ToString() == "F5")
                {
                    webView.Address = "localhost";
                }
                if (args.Key.ToString() == "F12")
                {
                    webView.ShowDevTools();
                }
                if (args.Key.ToString() == "Back")
                {
                    webView.Back();
                }
            };

            webView.RegisterJsObject("csharp", new CallbackObjectForJs());
            webView.Address       = "localhost";
            webView.FrameLoadEnd += OnLoadEnd;
            Content = webView;
        }