[introduction] I have sample WPF application. If I click a button, new window is opened. I need to wait some time for data to be loaded inside it. Rather than passively wait, I want to do some other stuff in the meantime. I can for example open some context menu. This situation is illustrated on the screen below:
This wait-for-me window, just after the loading is completed (data is ready to show), fires an event where focus is set to the grid:
void DataLoaded(object sender, EventArgs e)
{
grid.Focus();
grid.SelectedIndex = 0;
}
[current issue] Unfortunately, in the very same moment, our recently opened context menu has just disappeared. The focus has been forcefully stolen from it. Annoying final effect is shown below:
[desired effect] What would be the happy end? It would be no automatic focus, if user just changed it to any other element (like context menu). In the other words - do not steal the focus.
The code modification could be:
void DataLoaded(object sender, EventArgs e)
{
if (Magic.FocusNotChanged)
{
grid.Focus();
grid.SelectedIndex = 0;
}
}
But, what is the Magic? Some global publish subscribe mechanism which allows or denies automatic focus changes? Some handler which is spying focus changes?
BTW: This particular application shown above is just artificially extracted from much wider context. Do not pay much attention to the layout implemented here. Some generic mechanism has to be invented, not related to this specific button or context menu. Any clues? Regards.