c# - WPF 的 CefSharp 不显示

标签 c# asp.net .net wpf cefsharp

我通过 NuGet 在我的应用程序中安装了 CefSharp,然后在我的 app.xaml.cs OnStartup() 方法中对其进行了初始化。当我的应用程序运行时,我没有任何显示,也没有错误。将 View 切换为另一个不使用 CefSharp 的 View 正常显示。我似乎无法使用 CefSharp 呈现网页。

查看 [QuestHTMLView]

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
    </Grid.RowDefinitions>
    <cefSharp:ChromiumWebBrowser Grid.Row="0" Address="https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions" />
</Grid>

ViewModel [QuestHTMLViewModel]

public class QuestHTMLViewModel : Screen
{
}

ShellView(呈现前一个 View 的地方)

<xctk:BusyIndicator VerticalAlignment="Top" Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" IsBusy="{Binding IsBusy}">
    <ContentControl x:Name="ActiveItem" />
</xctk:BusyIndicator>

ShellViewModel(其中 CefSharp View 设置为 ActiveItem)[仅限构造函数]

    public ShellViewModel()
    {
        QuestHTML = new QuestHTMLViewModel();
        ActiveItem = QuestHTML;
    }

初始化

protected override void OnStartup(StartupEventArgs e)
{
    Cef.Initialize(new CefSettings());
    base.OnStartup(e);
}

最佳答案

您应该在 OnStartUp() 方法中初始化并显示 Window:

protected override void OnStartup(StartupEventArgs e)
{
   MainWindow = new MainWindow();
   MainWindow.ShowDialog();
   base.OnStartup(e);
}

并且不要忘记从 App.xaml 中删除 StartupUri 属性。 App.xaml 应该如下所示:

<Application x:Class="TestPlace.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

关于c# - WPF 的 CefSharp 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35233687/

相关文章:

c# - tabControl/tabitem 刷新困难

c# - 银光。绑定(bind)到数据对象的附加属性,不输入 getter

asp.net - 如何将重写规则应用于 ASP.NET 项目中包含的 HTML 文件?

c# - 是否有全局设置防止 sql 注入(inject)和 XSS? (ASP.NET)

c# - 为什么要使用 Func<string> 而不仅仅是字符串?

c# - WINMOBILE 将文件从 C# 上传到 php webservice

c# - 统一的 Firebase 身份验证登录总是返回一个新用户

asp.net - 使用 Asp.Net 连接到 Heroku Postgres 数据库

c# - 使用 ASP.NET Core 3.0 内置 API 从 .crt 和 .key 文件创建 X509Certificate2

.net - 为什么 WCF 需要 DTC 来处理事务流?