gpt4 book ai didi

c# - 如何在运行时在 WPF 中创建 CefSharp ChromiumWebBrowser

转载 作者:行者123 更新时间:2023-11-30 23:18:22 28 4
gpt4 key购买 nike

我关注了this演示如何在 WPF 中开始使用 CefSharp 的教程。

控件在 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>

如何通过在运行时创建 ChromiumWebBrowser 来实现同样的目的?

我试过这样的:

    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:

<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>

但是窗口是空白的。

最佳答案

我在 similar question 中找到了这个答案:

设置 Address 属性而不是调用 Load:

web.Address = "https://www.google.com";

关于c# - 如何在运行时在 WPF 中创建 CefSharp ChromiumWebBrowser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40959542/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com