我通过 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/