CefSharp WinForms browser hosted within WPF WinFormsHost - c#

I'm currently working on moving out kiosk software that runs Awesomium away and instead onto CefSharp.
Our main application is written in WPF and this work is using v45 of CefSharp
I'm aware that the WPF control has some serious performance issues, when compared side-by-side with the WinForms version hosted in a WindowsFormsHost, the smoothness of transitions etc is MUCH better.
To that end I'm looking to stick with this approach of embedding the WinForms ChromiumWebBrowser inside a WindowsFormsHost on the WPF window. This all works and however I'm having issues with getting touch support to work.
Our kiosks have touch screens and run Windows 7 / 8.1, the touch works flawlessly with the WPF control, however when using the WinForms embedded one touch doesn't work at-all.
As well as touch not working it also steals all Keyboard events and consumes them internally it seems, as none of my event handlers ever fire on the main WPF window.
If anyone has any ideas or can point me in the correct direction to try and solve this it would be hugely appreciated!
Thanks

The scenario your talking about is not well supported and as such there is not a lot of information. A lot of the problem your are seeing are likely because CEF is running it's message loop in a separate thread. If you turn MultiThreadedMessageLoop off, then you become responsible for calling Cef.DoMessageLoopWork(). I recently added a rough demo the WinForms Example. You can likely port this to WPF, though I've never tried.
https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.Example/CefExample.cs#L76
https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.WinForms.Example/Program.cs#L37
You are in somewhat uncharted territory there, so you'll have to do most of the leg work yourself.
For reference there are some ways to improve the WPF performance. They come with their own set of drawbacks though. See https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.Example/CefExample.cs#L58

Related

How to make non-modal MessageBox pop-ups for Unity project

Gday,
I am currently doing a small Unity project where the game takes place on the desktop, we have a creature that communicates with the player. It is currently severely limited with how it acts/reacts due to the only way that I can figure out how to make popups in the windows system style is through the use of the MessageBox function which is Modal (it suspends the application from running until the MessageBox has been answered or closed).
So I was wondering if there was any way to get the same effect without it suspending the entire application, I've tried looking into Forms however I can't get it to recognise it as a thing in VisualStudios. I have also looked at GUI.Window however doesn't create a window that looks like a Windows style popup.
What do yall reckon?
(Thankyou in advance)
In general, trying to mix Unity and WinForms is a really bad idea. They were built around completely different design philosophies and if you keep going down this path, they're going to keep fighting each other.
The best option here would be to create your own lookalike windows in-game. That would require quite a bit of work and infrastructure to set up at the beginning, but it would also give you full control over the style and behaviour of the dialogs.
Browse the asset store for assets that solve the problem for you. There are a number of dialog type assets you can grab and plug into your unity project to get you running quickly. A lot of them mimic windows features like moving around, scrolling or X to close.

How do I scale hybrid (WPF / WinForms) applications correctly

I am currenlty developing a plugin for an existing 3rd part system. The plugin exposes a GUI, which is defined to be WPF by the plugin framework. However, i have to integrate a legacy WinForms control that is hidden in a library (no source code available).
Using WinFormsHost works great, as long as the Display scaling is set to 100%. If the settings are different, my embedded WinForms control scales awkward and doesn't look good anymore.
If I create a WinForms Window and embed the control, scaling is fine.
If I create the same window from a WPF application / Window and push the WinForms window into the WPF window with HwndHost, scaling is awkward again.
It seems that scaling is only correct when i start my WinForms window in a separate process outside the 'WPF' environment.
I should be able to catch the separate process' window and get proper scaling, but communication into my legacy window may become tricky then.
Is there a way to get proper scaling without the detour via a separate process? I know that similar questions have been posted here, but so far i did not find what i was looking for.
Thanks in advance.

WPF and CefSharp: sluggish performance

I have successfully made a personal mini browser app in c# winforms.
Because I want some more fancy effects, I was considering to make a WPF app. So I tried the wiki tutorial and set up a simple WPF form with a browser, but noticed it has sluggish performance. It's even noticeable when selecting text in very simple webpage, or just when scrolling the page. Is there anything that can be done? If not, I guess it will be just winforms then, since that one behaves and performs well.
edit: my specs: http://users.telenet.be/dropbox/specs.html
WPF version of cefsharp uses different model of rendering than WinForms. In WPF it basically copies each frame into bitmap and you might imagine how slow it can become. This is especially noticeable on high-resolution screens. There are some options to improve that perfomance (see here for example), but in my experience (I tried all that options) non of them really helps to match WinForms. To run cefsharp smoothly in my WPF project I actually had to use WinForms version of cefsharp and host it inside WindowsFormsHost - this helps with perfomance problems but has it's caveats of course (for example you cannot partially hide WinForms hosted control behind WPF controls - it will always be rendered on top of everything). Still for now I consider this the only viable option, because high-resolution screens are now quite widespead.
This will disable WebGL, look at the source to determine which flags best suite your requirements. "grMain" is a Grid in Wpf
CefSettings s = new CefSettings();
s.SetOffScreenRenderingBestPerformanceArgs();
Cef.Initialize(s);
ChromiumWebBrowser wbMain = new ChromiumWebBrowser();
grMain.Children.Add(wbMain);

Any way to stop focussing a WPF textcontrol slowing application update performance?

I'm developing a C# WPF XAML-based Windows desktop application, and the UI is beautifully smooth and slick until I focus a textbox. Once focussed, the update rate of the whole UI is much lower. I'd estimate it all runs at the "full" (?) 60fps originally, dropping to more like 30fps after the text control gains focus. I've dug around all sorts of Microsoft documentation and advice on WPF performance, but nothing seems to mention the mere act of a control gaining focus being a problem. It's quite mystifying. I've tried to use the Windows Performance Toolkit to analyse the issue, but I'm getting nowhere. I've been able to do a klugey workaround in some scenarios with judicious use of Keyboard.ClearFocus() when clicking any other control, which returns the update rate to normal, but it's not great to have to do that.
This issue can be readily replicated - a brand new VS2015 WPF project, with a text box and a button will show the issue (add Keyboard.ClearFocus() to the button's click handler). This demonstrates it's nothing specific to my application code, it's a framework issue.
Does anyone have an idea why the described issue may be occurring, or how I may be able to resolve it?
Update: I've uploaded a sample project showing the issue, here: http://muuh.co.uk/SlowTextbox.zip

C# Hosting WPF in Winforms

I am looking at the possibility to host a WPF control inside a Winforms application. The reason for this is some animations inside the WinForms application. WPF should be able to support this way better because it (mostly) uses the graphic card to render instead of the CPU.
Now my question:
Are there any cons of hosting a WPF Control inside a Winforms application? Does the WPF Control still use the graphic card for the rendering or does it loose some of its advantages?
Thanks for your help. If you have any inputs or tips feel free to tell me.
EDIT
I found a similar question (but maybe that one is a bit more general, I focus more on the rendering):
Any disadvantage to using an ElementHost to host a WPF UserControl in a Winform application?
Mainly it behaves very like in a normal WPF Application.
But sometimes there are little unexpected behaviors. And it should use the hardware rendering if it would be using in normal wpf applications (depending on your configuration)
Sometimes i had problems with correctly recevien some keyboard keys in events. but there are a lot of artikels descriping the problems and solutions.
For example with some controls you could have problems catching keys. So you should have a look at System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop
-> also see this blogpost

Categories

Resources