CefSharp For WPF Not Displaying

本文关键字:Displaying Not WPF For CefSharp | 更新日期: 2023-09-27 18:33:23

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

View [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(呈现上一个视图的位置)

<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);
}

CefSharp For WPF Not Displaying

您应该初始化并显示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>