Restore Tab Focus From CEFSharp - wpf

I have a WPF application that hosts a CEF browser using CEFSharp. I've found that if I navigate my application's controls using keyboard tabbing, I can cycle through my controls without problem. Once focus makes it to the ChromiumWebBrowser control, focus shifts to within the current web page, as expected. However, once focus makes it within the web page, I can never get focus back out to my application. Hitting tab at the end of the html document just moves focus back to the top of the page, rather than pushing focus back to my application.
I have tried implementing IFocusHandler, but IFocusHandler.OnSetFocus() gets called right when the application is launched and none of the handler methods ever get called again.
How can I move focus back to the host application when tabbing reaches the end of a document in CEFSharp?
UPDATE:
Since this is a bug in CEF that has yet to be fixed, here are a couple relevant links to check on later to see if any progress has been made.
CEFSharp issue: https://github.com/cefsharp/CefSharp/issues/721
CEF issue: https://bitbucket.org/chromiumembedded/cef/issues/1826/focus-handler-not-called-for-offscreen

Related

Keyboard focus problems

I am needing to use the DotNetBrowserControl inside of another application (I am an add-in in the application). The application is written in WPF and has some WinForms components.
When I try to use the WPFBrowserView in the app I can never get focus to go into the Browser Window at all (even when clicking on a the google search box for example).
When I try to use the WinformsBrowserView inside of a WindowsFormsHost control I am able to get focus into the google search box by clicking on it. However once I click focus out of the browser control (to a WPF textbox for example) I can never get Keyboard focus back into the browser (even when clicking on a textbox in the browser).
It seams I am closest on getting the WInformsBrowserView working. Does anyone have any advice on how to force focus into the browser window? Even if I could programmatically force this to happen it would be a huge help.
We have implemented force focus feature for DotNetBrowser, but it is not yet present in the current version. We plan to add it to the next version of DotNetBrowser. If you need a build with this feature present, please get in touch with us via DotNetBrowser support email, and we will provide you with a preview build.

WPF Popup getting closed in a seamless citrix mode

First things first, this problem only happens while working in Citrix XenApp seamless mode (which, in simplest of words means the actual app is running on some citrix host but it is simulated as residing in your own desktop). I will take this up with Citrix Support as well but just wanted to poll the group in case someone faced a problem like this before.
I have a WPF app which uses Winforms NotifyIcon to reside in system tray until mouse clicked. In Citrix seamless mode, as user clicks the icon in system tray, the popup flashes and immediately closes on its own.
The Popup window is a vanilla one created with StaysOpen as FALSE and same works in every other environment.
Any suggestions ? This is what I've noticed so far:
The window stays open if I use StaysOpen as true. But then I don't have a way to close the window manually when it loses focus. LostFocus Event doesn't get fired on popup when user clicks outside.
In citrix seamless mode, the MouseEnter event is captured but MouseLeave is NOT so the approach of closing the window if user mouse is outside the window for X secs is not achievable.
Tried the workaround of starting the popup with Staysopen as FALSE and then reset staysopen after like 2 secs so that the pop sticks. It works but a soon as I set StaysOpen as FALSE once the timer is hit, the pop up closes on its own.
Without all these workarounds, if a user quickly clicks (leftclick) on the window before it disappears, the pop up sticks so I tried few ways to simulate the mouse click on the popup as it opens up but that doesn't cut it either.
Thanks
I can't help you with specific advice for tweaking your app to work around the issue, however there is always the hit it very hard with a hammer approach, i.e. tell consumers of your app to disable seamless for your application:
http://support.citrix.com/article/CTX116357/
Update: I pinged the original seamless dev - he said it sounds like a bug where seamless is not correctly routing all the necessary mouse messages between client and server. He said the best way to diagnose this was to run the Spy++ tool on the XenApp server and on the client, and then compare the messages each side sees to identify what messages are not getting translated. Since it sounds like a genuine bug, your best bet is to raise a support ticket with Citrix support and provide them with a sample app that can repro the bug.

In Silverlight, How can I disable Back and Forward navigation using browser buttons?

I'm using the Navigational Framework in Silverlight 4. I'm starting to believe that this was a mistake as the browser buttons are really screwing things up for users. For instance, when a child window is opened the user believes they can close the window by pressing the back button. It doesn't close the window obviously, it just navigates the parent page back a step. The end result is a messed up data set. I'm fed up with the little control I have over the navigation of my application; forward and back buttons are anachronistic. Web applications don't work that way anymore. Please someone tell me how I can disable their functionality; that is, cancel navigation when it is started from one of these buttons.
Remove this code from your html page which holds your silverlight XAP:
<iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
This is the history frame.
You will likely have to do this in the actual web/asp.net page, as Silverlight has no real control over the browser.
Some workarounds in this article:
http://lennilobel.wordpress.com/2009/07/26/defeat-the-evil-back-button-in-your-asp-net-applications/

Can Silverlight hook into the browser's Edit > Cut/Copy/Paste menu items?

We have a Silverlight app that contains a grid, and we've added support for selecting multiple cells, copying their contents to the clipboard, and pasting back elsewhere in the grid. Currently the user invokes the Copy and Paste commands by either clicking a toolbar button inside our Silverlight app, or using the standard keyboard shortcuts, which we catch with a KeyDown event.
Is it possible to also hook into the browser's native Edit menu, and the Cut, Copy, Paste, etc. menu items that are built into the browser? For example, can the user drop down the Firefox button (or press Alt+E to drop down the classic Edit menu), click the Copy item in Firefox's menu, and have some sort of Copy command be relayed to the focused control in my Silverlight app? Same thing for the equivalent menus in IE, Chrome, Opera, etc.
I wouldn't be surprised if this can't be done, since even long-established browser plug-ins like Adobe Reader have their own buttons for copy/paste and even print, rather than hooking into the browser's native menus. But I've never programmed to a browser's plug-in model, so I don't know for sure what's possible.

Set system focus on my application

I have an application that will mainly operate in the background. I want certain system events that it handles to cause the app to steal focus from the foreground app, whatever that is. But UIElement.Focus() seems to only set the focus within the WPF app. That is, if the WPF app already has the focus as a whole, then Focus() sets the focus to the right control. But I need to steal focus from another app and put it on my app. How can I do this?
I do not want a system modal dialog. That is, after the window steals focus, it should be possible for the user to immediately switch to another app without dismissing my app's window.
The app may already been in a restored, minimized, or even "minimize to tray" state when it needs to steal system focus. So assuming that it is minimized and stealing focus while restoring the window is not acceptable.
If you don't mind doing som p/invokes, the SetForegroundWindow function should be able to help you:
http://pinvoke.net/default.aspx/user32/SetForegroundWindow.html

Resources