CefSharp对于WPF不显示

3

我通过NuGet在我的应用程序中安装了CefSharp,然后在我的app.xaml.cs的OnStartup()方法中初始化它。当我的应用程序运行时,什么都没有显示,也没有出现错误。将视图切换到另一个不使用CefSharp的视图会正常显示。我似乎无法让网页使用CefSharp渲染。

视图[QuestHTMLView]

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

视图模型 [QuestHTMLViewModel]

public class QuestHTMLViewModel : Screen
{
}

ShellView(上一个视图呈现的位置)

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

ShellViewModel(其中 CefSharp 视图被设置为 ActiveItem)[仅构造函数]

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

初始化

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

你是否正在使用Prism框架? - StepUp
我正在使用Caliburn Micro来实现MVVM模式。 - Bacon
你尝试过剥离MVVM框架,只是让基础功能正常工作吗?你可以在https://github.com/cefsharp/CefSharp.MinimalExample看到一个基本的工作示例。 - amaitland
1个回答

0

你应该在 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>

可能有一些误解。我已经更新了我的原始帖子。 - Bacon
@Jeff 你确定你的 viewmodel 已经被加载,并且作为 ViewDataContext 类被使用了吗? - StepUp
是的,ViewModel 正在加载。如果我将 cefSharp:ChromiumWebBrowser 更改为普通的 WebBrowser,它会显示 HTML。但是 WebBrowser 的问题是它无法正确渲染我的 .css。 - Bacon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接