如何在 WPF 中在运行时创建 CefSharp ChromiumWebBrowser
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40959542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create CefSharp ChromiumWebBrowser at runtime in WPF
提问by RaelB
I have followed thistutorial that shows how to get started with CefSharp in WPF.
我遵循了本教程,该教程展示了如何在 WPF 中开始使用 CefSharp。
The control is declared in xaml:
控件在 xaml 中声明:
<Window x:Class="Sample1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
Title="MainWindow" Height="550" Width="625">
<Grid>
<cefSharp:ChromiumWebBrowser Grid.Row="0"
Address="https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions" />
</Grid>
</Window>
How can I achieve the same by creating the ChromiumWebBrowserat runtime?
如何通过ChromiumWebBrowser在运行时创建来实现相同的目标?
I have tried something like this:
我试过这样的事情:
public partial class MainWindow : Window
{
ChromiumWebBrowser web;
public MainWindow()
{
InitializeComponent();
web = new ChromiumWebBrowser();
web.Load("https://www.google.com");
Grid.SetRow(web, 0);
Grid1.Children.Add(web);
}
}
XAML:
XAML:
<Window x:Class="CefSharpWPFDemo.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:local="clr-namespace:CefSharpWPFDemo"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="434.607" Width="656.899" WindowStartupLocation="CenterScreen">
<Grid x:Name="Grid1">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
</Grid>
</Window>
But the window is blank.
但是窗口是空白的。
回答by RaelB
I found this answered in a similar question:
我在一个类似的问题中找到了这个答案:
Set Addressproperty instead of calling Load:
设置Address属性而不是调用 Load:
web.Address = "https://www.google.com";

