I have an application in which there is a main window containing a bunch of things. From time to time, the user will do something, in response to which I want to show something else completely in the main window, temporarily hiding what is there.
I do this by making the outer element in the main window a grid without specific rows or columns. Each element in the grid, then completely fills one single cell in the grid, leaning on top of the rest.
So, my usual grouping is in the first grid element, and my temporary something else is UserControl as the second grid element, usually set by Visibility = Collapsed.
With the exception of KeyBinding, everything is working fine. When the corresponding command is run in a regular group of things, the visibility in UserControl is set to Visible and completely covers the usual bunch of things. When the user clicks the close button in UserControl, he becomes compensated again, and he disappears, and the usual bunch of things appear.
My problem is with KeyBindings. I have several defined in UserControl - which should not be defined in the main window - and they do not work. Rather, they work fine when I click inside the UserControl, but they don't work until I do.
I need them to work as soon as the UserControl becomes visible, without requiring the user to click or tab in the UserControl itself.
I suppose this has something to do with keyboard focus, but I could not find a way to focus on UserControl. Here's the thing - the only element in UserControl is the tab control, all of whose tabs are dynamically created using templates. At compile time, there are no elements that I can explicitly specify and go to KeyBoard.Focus ().
So, am I right in thinking that this is the lack of focus that causes the problem? And if so, how can I set the focus on an element in TabControl when I donβt even know how many tabs there are, let alone what is selected?