1

全部:

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

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

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

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

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

Xaml 部分:

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

代码背后就像

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

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

4

1 回答 1

3

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

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

于 2012-11-27T15:51:06.113 回答