Files
Alex Maitland f43cd64c55 Import CefSharp.Wpf.HwndHost into main repository. (#4981)
* HwndHost - Initial import

* HwndHost - Add Example to solution and use common IWpfChromiumWebBrowser interface

* HwndHost - Update UpdateNugetPackages.ps1

* HwndHost - Add Nuspec

* HwndHost Example - Upgrade version

* HwndHost Example - Try non self contained build for debug and release

* Test - Add basic HwndHost tests

Probably need to revisit these, little bit hacky creating the window

* HwndHost - Allow any RequestContext that inherits from Core.RequestContext

Cheery pick of https://github.com/cefsharp/CefSharp.Wpf.HwndHost/pull/31

* HwndHost Example - Disable arm64

Example will be removed shortly, so it doesn't matter too much now.
It will be moved to MinimalExample and the Wpf Example expanded

* HwndHost - Delete delegate command

* Upgrade packages

* Nuget - Move Nuspec file to PackageReference folder

---------

Co-authored-by: amaitland <307872+amaitland@users.noreply.github.com>
2025-01-18 06:40:48 +10:00

54 lines
1.9 KiB
C#

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace CefSharp.Wpf.HwndHost.Example.Handlers
{
public class DisplayHandler : CefSharp.Handler.DisplayHandler
{
private Border parent;
private Window fullScreenWindow;
protected override void OnFullscreenModeChange(IWebBrowser chromiumWebBrowser, IBrowser browser, bool fullscreen)
{
var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser;
_ = webBrowser.Dispatcher.InvokeAsync(() =>
{
if (fullscreen)
{
//In this example the parent is a Border, if your parent is a different type
//of control then update this code accordingly.
parent = (Border)VisualTreeHelper.GetParent(webBrowser);
//NOTE: If the ChromiumWebBrowser instance doesn't have a direct reference to
//the DataContext in this case the BrowserTabViewModel then your bindings won't
//be updated/might cause issues like the browser reloads the Url when exiting
//fullscreen.
parent.Child = null;
fullScreenWindow = new Window
{
WindowStyle = WindowStyle.None,
WindowState = WindowState.Maximized,
Content = webBrowser
};
fullScreenWindow.Loaded += (_,_) => webBrowser.Focus();
fullScreenWindow.ShowDialog();
}
else
{
fullScreenWindow.Content = null;
parent.Child = webBrowser;
fullScreenWindow.Close();
fullScreenWindow = null;
parent = null;
}
});
}
}
}