c# - In what situations will WPF give keyboard focus back to the main window? -
c# - In what situations will WPF give keyboard focus back to the main window? -
in wpf application i'm working on, have menuitem
2 items in it. when menuitem
clicked, takes keyboard focus , opens submenu. when menuitem
clicked again, submenu closed , reason, main window takes keyboard focus. need menuitem
maintain focus.
i have been told in other situations, main window may given keyboard focus - instance, if command has keyboard focus , isenabled
or isvisible
becomes false
. in situations happen? i've been googling crazy haven't found info this.
as far can tell, expected behavior. wpf menus focus scopes default, command within menu receives focus won't alter main logical focus of window. also, wpf controls phone call keyboard.focus(null);
(e.g. button
when clicked). phone call has effect of returning keyboard focus main logical focus. suspect happening when menu closed.
try disabling focus scope on menu: <menu focusmanager.isfocusscope="false">
when menu item receives keyboard focus, , it's not in focus scope, gets main logical focus. means keyboard.focus(null)
phone call maintain focus on menu item. jowever, prevent commands in submenu returning focus non-menu window content, routed commands won't able find target.
see "for focusscope designed?" in using wpf focusscope.
c# wpf focus
Comments
Post a Comment