-
Notifications
You must be signed in to change notification settings - Fork 7
Extension
Mohammed Osama Mohamed Sayed Ahmed edited this page Apr 27, 2019
·
4 revisions
CefSharp Version 73.1.120-pre01 (73.0.3683.75)
Handler/Extension/Extension.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CefSharp;
namespace Example.Handler.Extension {
public class Extension : IExtension {
private string showModalDialog;
private string v;
public Extension(string v, string showModalDialog)
{
this.v = v;
this.showModalDialog = showModalDialog;
}
public string Identifier
{
get
{
return null;
}
}
public bool IsLoaded
{
get
{
return true;
// throw new NotImplementedException();
}
}
public IRequestContext LoaderContext
{
get
{
return null;
// throw new NotImplementedException();
}
}
public IDictionary<string, IValue> Manifest
{
get
{
return null;
// throw new NotImplementedException();
}
}
public string Path
{
get
{
return null;
// throw new NotImplementedException();
}
}
public bool IsSame(IExtension that)
{
return true;
/// throw new NotImplementedException();
}
public void Unload()
{
/// return;
// throw new NotImplementedException();
}
}
}
public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
var headers = request.Headers;
headers["Custom-Header"] = "My Custom Header";
request.Headers = headers;
return CefReturnValue.Continue;
}
Anyone got an answer for my question above re loading a page into the control when the WPF TabItem it is on it doesn't have focus?
@nzmike99 The default WPF TabControl
isn't really suitable for hosting a browser, see
When I add the ChromiumWebBrowserWithScreenshotSupport.cs file to the CefSharp.Wpf.Example project it needs the "using GalaSoft.MvvmLight.Command; " dependency which destroys the project with errors
@jeremiahjordani_twitter You could use any Delegate/RelayCommand implementation you like. Pretty common for WPF apps to have one.
If you don't have one then just change the access modifier for the paramaterless TakeScreenshot so it's usable in your instance. The command is entirely optional.
private void /*Btn*/Sceenshot_Click(object sender, RoutedEventArgs e)
{
/*
//CefSharp - Quick and Dirty Screenshot with no class dependency
MessageBox.Show("Take screenshot");
double dWidth = (webCefSharpChromiumWebBrowser.ActualWidth);
double dHeight = (webCefSharpChromiumWebBrowser.ActualHeight);
int actualWidth = 0;
int actualHeight = 0;
actualWidth = Convert.ToInt32(dWidth);
actualHeight = Convert.ToInt32(dHeight);
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(actualWidth, actualHeight, 90, 90, PixelFormats.Pbgra32);
renderTargetBitmap.Render(webCefSharpChromiumWebBrowser);
PngBitmapEncoder pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
using (Stream fileStream = File.Create(@"C:\SaveFolderName\apollo.png")) //uses System.IO for fileStream
{
pngImage.Save(fileStream);
}
*/
}
[C#
] TakeScreenshot [WPF
]
/*Here is an example that reuses the image that's already rendered to the screen.*/
var template = Browser.Template;
var image = (System.Windows.Controls.Image)template.FindName("PART_image", Browser);
var pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create((System.Windows.Media.Imaging.BitmapSource)image.Source));
var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot" + DateTime.Now.Ticks + ".png");
using (var fileStream = File.Create(screenshotPath))
{
pngImage.Save(fileStream);
}