首页 新闻 会员 周边

WPF嵌入一个chrome浏览器,没有显示是怎么回事?

0
悬赏园豆:5 [已解决问题] 解决于 2022-02-10 14:22

WPF代码

<Window x:Class="WpfApp2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
        xmlns:cef="clr-namespace:CefSharp;assembly=CefSharp.Core"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="使用Chrome浏览器" Height="450" Width="800">
    <Grid Name="grid1">
        <wpf:ChromiumWebBrowser x:Name="browser" Address="http://www.baidu.com" />
    </Grid>
</Window>

运行之后,什么都没有显示,一片空白,感觉象是被隐藏了,或者完全透明了一样

 

背锅狼的主页 背锅狼 | 初学一级 | 园豆:62
提问于:2022-02-08 17:43
< >
分享
最佳答案
0

我测试了一下,.netframework4.6 使用cefsharp.wpf 97.1.61,正常可以显示网页。

有可能你没有安装vc++分发库吧,
去这里下载最新的安装一下
https://docs.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170

要仔细阅读一下github上的doc,地址是https://github.com/cefsharp/CefSharp/wiki/
nuget安装CefSharp.Wpf后会弹出一个readme,可以阅读一下。

还有就是看看visual studio的output窗口里的输出内容,通常会有一些有用的信息。

收获园豆:5
xsz1234 | 初学一级 |园豆:39 | 2022-02-09 11:12

分发库已经装了,还是老样子,照理说如果有什么库没装,应该运行出个异常才对啊

上它的github下载了 Example 编译运行都没出错,但就是浏览器不展示出来

背锅狼 | 园豆:62 (初学一级) | 2022-02-09 17:12

@血狼一族:
代码没问题,运行异常一般在output窗口里有显示。
你自行按照官方提供的troubleshooting处理一下

`Basic Troubleshooting:

  • Minimum of .Net 4.5.2
  • Minimum of Visual C++ 2019 Redist is installed (either x86 or x64 depending on your application).
  • Please ensure your binaries directory contains these required dependencies:
    libcef.dll (Chromium Embedded Framework Core library)
    icudtl.dat (Unicode Support data)
    chrome_elf.dll(Crash reporting library)
    snapshot_blob.bin, v8_context_snapshot.bin (V8 snapshot data)
    locales\en-US.pak, chrome_100_percent.pak, chrome_200_percent.pak, resources.pak, d3dcompiler_47.dll, libEGL.dll, libGLESv2.dll, swiftshader/libEGL.dll, swiftshader/libGLESv2.dll
    • Whilst these are technically listed as optional, the browser is unlikely to function without these files.
    • See https://github.com/cefsharp/CefSharp/wiki/Output-files-description-table-(Redistribution) for details
      CefSharp.Core.dll, CefSharp.dll, CefSharp.Core.Runtime.dll
      CefSharp.BrowserSubprocess.exe, CefSharp.BrowserSubProcess.Core.dll
      • These are required CefSharp binaries that are the common core logic binaries of CefSharp.
        One of the following UI presentation libraries:
        CefSharp.WinForms.dll
        CefSharp.Wpf.dll
        CefSharp.OffScreen.dll
  • Additional CEF files are described at: https://github.com/cefsharp/CefSharp/wiki/Output-files-description-table-(Redistribution)
  • NOTE: CefSharp does not currently support CEF sandboxing.
  • By default CEF has it's own log file, Debug.log which is located in your executing folder. e.g. bin
    `
xsz1234 | 园豆:39 (初学一级) | 2022-02-10 09:05
其他回答(1)
0

已经解决了

其实啥毛病都没有,因为公司的电脑都装了加密客户端,加密软件把几个 bin 文件给加密了,导致运行时读不到

还是感谢热心网友的帮助

背锅狼 | 园豆:62 (初学一级) | 2022-02-10 14:22

微软自己有出了一个WebView2来代替老旧的WebBrowser,基于Edge(Chromium),
感兴趣也可以通过nuget安装试用一下,Microsoft.Web.WebView2。
需要有安装edge浏览器或者下载安装webview2 runtime
功能也很强大

支持(0) 反对(0) xsz1234 | 园豆:39 (初学一级) | 2022-02-11 01:04

@ilovedotnet: 

好的,会试一下。主要是我在WPF程序里里要做很多图表,这方面的资源太少了,而WEB版的图表资源反而很多,因此嵌入一个浏览器是最好的办法

支持(0) 反对(0) 背锅狼 | 园豆:62 (初学一级) | 2022-02-11 11:40

@血狼一族: 如果是chart图的话,可以试试一个是livecharts,一个是scottplot.前者花里花俏动画效果好看,但性能一般,后者类似python的matplotlib朴素的效果,性能还可以,都是开源项目,github有源码,可以搜索了解一下。
https://github.com/beto-rodriguez/Live-Charts
https://scottplot.net/

支持(0) 反对(0) xsz1234 | 园豆:39 (初学一级) | 2022-02-11 13:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册