Awesomium WPF WebControl 设置 .Source 属性不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13524844/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:20:27  来源:igfitidea点击:

Awesomium WPF WebControl Setting .Source property does not work

wpfweb-controlsawesomium

提问by wsw

ALl:

全部:

Hopefully someone is using Awesomium in WPF as I am doing now.

希望有人像我现在一样在 WPF 中使用 Awesomium。

I have a WPF control containing a WebControl which I want to dynamically set the source

我有一个包含 WebControl 的 WPF 控件,我想动态设置源

However, it seems that setting .Source does not work at all. It will always stay in the page that the source is set the very first time.

但是,似乎设置 .Source 根本不起作用。它将始终停留在第一次设置源的页面中。

Version I am using now is Awesomium 1.7 Rc3

我现在使用的版本是 Awesomium 1.7 Rc3

Basically I updated the sample code provided in Awesomium 1.7 Rc3 sdk, project

基本上我更新了 Awesomium 1.7 Rc3 sdk 中提供的示例代码,项目

Xaml Part:

Xml部分:

<Grid SnapsToDevicePixels="True">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
    <Button x:Name="btn" Click="Button_Click" Content="Navigate" Width="500" Height="100"/>
    <awe:WebControl Grid.Row="1"
        Name="webControl" 
        Source="http://stackoverflow.com"            
        ShowCreatedWebView="OnShowNewView" Width="900" Height="1000"/>            
</Grid>

Code Behind is like

代码隐藏就像

    public MainWindow()
    {
        WebCore.Initialize( new WebConfig() { LogLevel = LogLevel.Verbose } );
        InitializeComponent();
    }

    protected override void OnClosed( EventArgs e )
    {
        base.OnClosed( e );
        webControl.Dispose();
        WebCore.Shutdown();
    }

    private void OnShowNewView( object sender, ShowCreatedWebViewEventArgs e )
    {
        if ( !webControl.IsLive )
            return;
        e.Cancel = true;
        webControl.Source = e.TargetURL;
    }

    static int i = 0;
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        if (i % 2 == 0)
            this.webControl.Source = new Uri("http://yahoo.com.sg");
        else
            this.webControl.Source = new Uri("http://google.com.sg");

        i++;
    }

When I click the button, I suppose that webcontrol should toggle between yahoo and google, but nothing happens when I click.

当我单击按钮时,我想 webcontrol 应该在 yahoo 和 google 之间切换,但是当我单击时没有任何反应。

回答by HotN

You're code is correct and is using the API as the documentation instructs. However, this turns out to be a bug with Awesomium 1.7RC3. See this postin the support forums.

您的代码是正确的,并且正在按照文档说明使用 API。然而,事实证明这是 Awesomium 1.7RC3 的一个错误。请参阅支持论坛中的此帖子

You can still use WebControl.LoadURL()for this release.

对于此版本,您仍然可以使用WebControl.LoadURL()