I have an app which runs fine as a simple WPF app having an event handler on GotFocus at the main window level like so :
private void MainWindowGotFocus(object sender, RoutedEventArgs e)
{
var element = FocusManager.GetFocusedElement(this) as FrameworkElement;
if (element != null)
{
//...
However this behaves strangely when set as a XBAP app (almost exactly the same code - the main visual element is Page and not Window but the event is still available and triggered).
In that case (XBAP/wpf browser application) element is always null.
Any ideas? :(
Well thanks to a colleague of mine (Bogdan R.) we've discovered that FocusManager.IsFocusScope has different default values for Window (WPF) and Page (XBAP), namely it is false for the latter.
Simply setting FocusManager.IsFocusScope on the Page element fixes the problem.
could also try to use Keyboard.FocusedElement instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With