My application uses the virtual keyboard. The keyboard becomes hidden when the charms bar is opened, but it will always reappear when the charms bar is closed. I want to control whether it reappears or not.
My program has several folders with editable files, and the virtual keyboard is used to edit the files. In the charm bar's 'Settings' selection I've added a control over which folders/files are displayed. The problem occurs when the user has the virtual keyboard open while editing a file, then goes to the charms bar to disable the folder that that file is in. I've coded things such that the file is closed when this happens, but once the user closes the charms the keyboard will automatically reopen... and let the user keep typing and altering the data! They can even finagle the file to re-open while its folder is disabled!
I have read several other questions of a similar nature, but none of them have the added element of the charm bar. I think Windows 8 makes a note or flags the virtual keyboard to reopen when I open the charm bar while the keyboard is up, and telling the keyboard to close doesn't touch that flag (and anyway I can't tell it to close at a point when it's already closed).
If I can figure out how to handle that hypothetical flag, or instead get some code to execute immediately after the keyboard reopens, I can get the rest of it to work. Any advice?
UPDATE:
I found a work-around: all keyboard input now goes through a filter that checks if the folder/file is still active, else ignore input. Not perfect but serviceable for my needs. Original question remains unanswered.
While I do not know of any way to activate code when the charms bar closes, it is sufficient to close the keyboard before it opens, and therefore not be set to reopen after using the charms bar.
This is achieved by adding this to the initializer:
Window.Current.Activated += Current_Activated;
and then writing the method:
private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
As for how to lose focus after triggering the method, I suggest looking here.