Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF - Add Experimental LifeSpanHandler capable of hosting popups using TabControl/ContentControl #4285

Closed
2 tasks done
amaitland opened this issue Oct 25, 2022 · 1 comment
Assignees
Milestone

Comments

@amaitland
Copy link
Member

amaitland commented Oct 25, 2022

Add LifeSpanHandler implementation capable of hosting popups as Tabs/Controls

There are still some CEF bugs that mean this is still classed as experimental. One such issue was reported at #3847 (comment)

It's important to remember that only bugs in CefSharp can be fixed directly in this repository, CEF has it's own issue tracker at https://bitbucket.org/chromiumembedded/cef

  • Update Wiki
  • Further testing

Example:

// Open popup (browser) in a new WPF Window
// Can be used to host in TabControl/ContentControl/etc
browser.LifeSpanHandler = CefSharp.Wpf.Experimental.LifeSpanHandler
	.Create()
	.OnPopupCreated((ctrl, targetUrl, targetFrameName, windowInfo) =>
	{
		var windowX = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
		var windowY = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
		var windowWidth = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
		var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;
		var popup = new System.Windows.Window
		{
			Left = windowX,
			Top = windowY,
			Width = windowWidth,
			Height = windowHeight,
			Content = ctrl,
			Owner = Window.GetWindow(browser),
			Title = targetFrameName
		};
		popup.Closed += (o, e) =>
		{
			var w = o as System.Windows.Window;
			if (w != null && w.Content is IWebBrowser)
			{
				(w.Content as IWebBrowser)?.Dispose();
				w.Content = null;
			}
		};
	})
	.OnPopupBrowserCreated((ctrl, browser) =>
	{
		ctrl.Dispatcher.Invoke(() =>
		{
			var owner = System.Windows.Window.GetWindow(ctrl);
			if (owner != null && owner.Content == ctrl)
			{
				owner.Show();
			}
		});
	})
	.OnPopupDestroyed((ctrl, popupBrowser) =>
	{
		//If browser is disposed then we don't need to remove the tab
		if (!ctrl.IsDisposed)
		{
			var owner = System.Windows.Window.GetWindow(ctrl);
			if (owner != null && owner.Content == ctrl)
			{
				owner.Close();
			}
		}
	}).Build();
@amaitland amaitland changed the title Enhancement - WPF Add Experimental LifeSpanHandler capable of hosting popups as Tabs/Controls WPF - Add Experimental LifeSpanHandler capable of hosting popups as Tabs/Controls Oct 25, 2022
@amaitland amaitland self-assigned this Oct 25, 2022
@amaitland amaitland added this to the 107.1.x milestone Oct 25, 2022
amaitland added a commit that referenced this issue Oct 25, 2022
@amaitland amaitland changed the title WPF - Add Experimental LifeSpanHandler capable of hosting popups as Tabs/Controls WPF - Add Experimental LifeSpanHandler capable of hosting popups using TabControl/ContentControl Oct 25, 2022
amaitland added a commit that referenced this issue Nov 2, 2022
- Rename the delegates (add prefix)

Issue #4285
amaitland added a commit that referenced this issue Nov 2, 2022
- Rename the delegates (add prefix)

Issue #4285
@amaitland
Copy link
Member Author

The delegates have been renamed to add a LifeSpanHandler prefix.

This will be included in M107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant