My project based on Cef version 3.2526.1373 and Xilium revision 0bd98ba7dce1(3.2526.1366) .
I override OnBeforePopup:
- Code: Select all
protected override void OnBeforePopup(BeforePopupEventArgs e)
{
base.OnBeforePopup(e);
e.Handled = false;
CefWebBrowser clone = new CefWebBrowser();
e.WindowInfo.SetAsChild(clone.Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });
Window1 parent = new Window1();
parent.Title = "TestPage";
WindowsFormsHost a = parent.FindName("browserParent") as WindowsFormsHost;
a.Child = clone ;
parent.Show();
}
Window1.xaml is :
- Code: Select all
<Window x:Class="Test.Window1"
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"
mc:Ignorable="d" Height="800" Width="1024">
<Grid>
<WindowsFormsHost x:Name="browserParent">
</WindowsFormsHost>
</Grid>
</Window>
By this ,parent not show the page.
if use Window1 as the e.WindowInfo.ParentHandle,will show the page,
- Code: Select all
Window1 parent = new Window1();
parent.Show();
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(parent).Handle;
e.WindowInfo.SetAsChild(hwnd, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });
when set StartUrl of CefWebBrowser,works well:
- Code: Select all
CefWebBrowser clone = new CefWebBrowser() { StartUrl = "http://google.com"};
Window1 parent = new Window1();
parent.Title = "TestPage";
WindowsFormsHost a = parent.FindName("browserParent") as WindowsFormsHost;
a.Child = clone ;
parent.Show();
Could anyone help me ,thanks very much.