全部:
希望有人像我现在一样在 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 之间切换,但是当我单击时没有任何反应。