2016-12-04 72 views
1

我遵循this教程,該教程展示瞭如何開始使用WPF中的CefSharp。如何在運行時在WPF中創建CefSharp ChromiumWebBrowser

<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在運行時實現相同的:

控制在XAML中聲明?

我已經試過這樣的事情:

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> 

但窗口是空白。

回答

1

我發現這個回答在similar question

Address屬性,而不是調用加載:

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