c# - My inputcommand keybinding to main window does not work when child window is focussed(same wpf window)? -
i facing 1 problem input command key binding. here explain situation... have binded input command key binding below,
<window x:class="defaultbehavior_keybinding.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <window.inputbindings> <keybinding key="f2" command="{binding testcommand}"/> </window.inputbindings> <grid> <button content="add" width="100" height="35" grid.row="0" name="emptybutton" click="emptybutton_click"/> </grid>
it works fine. opened new wpf child window in button click event below,
public partial class mainwindow : window { public icommand testcommand { get; private set; } public mainwindow() { this.testcommand = ........some command attached here... initializecomponent(); this.datacontext = this; } private void emptytabbutton_click(object sender, routedeventargs e) { window childwindow = new window() { title = "childwindow", width = 200, height = 300 }; childwindow.show(); } }
after opening child window, key binding main window not working when child window focused. if switch focus main window means, fine.
i know, both main window , child window independent each other.
but question is, how can make work child window focussed when binded keybinding main window only. don't want set binding each child window because in case using lot of child windows.
any 1 please provide suggestion me?
the key bindings work if form focused. redirect every command in new window main window
change constructor of new window accept main window , save window:
mainwindow mainwindow; public window(mainwindow w) { mainwindow = w; }
whenever keybinding executes this:
mainwindow.tabpress();
and show window with
window childwindow = new window(this) { title = "childwindow", width = 200, height = 300 }; childwindow.show();
Comments
Post a Comment