commandbinding - WPF Application Menu disabled when the focus is on a Textbox and wont work until app restart -


i having problem appmenus in sample wpf application.

window2.xaml:

<window x:class="samplewpfapp.window2"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="clr-namespace:samplewpfapp"     name="rootwindow"     title="window2" height="600" width="800"> <window.inputbindings>     <keybinding gesture="ctrl+n" command="applicationcommands.new" commandtarget="{binding elementname=topmenu}" />     <keybinding gesture="ctrl+f1" command="{x:static local:topmenu.showhelp}" commandtarget="{binding elementname=topmenu}" /> </window.inputbindings>     <dockpanel>     <local:topmenu dockpanel.dock="top" x:name="topmenu" />     <contentcontrol>         <local:home x:name="maincontent" />     </contentcontrol> </dockpanel> 

topmenu.xaml

<usercontrol x:class="samplewpfapp.topmenu"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"           xmlns:local="clr-namespace:samplewpfapp"          mc:ignorable="d"           d:designheight="300" d:designwidth="300"> <usercontrol.inputbindings>     <keybinding gesture="ctrl+n" command="applicationcommands.new" />     <keybinding gesture="ctrl+f1" command="{x:static local:topmenu.showhelp}" /> </usercontrol.inputbindings> <usercontrol.commandbindings>     <commandbinding command="applicationcommands.new" executed="newexecuted" canexecute="newcanexecute"/>     <commandbinding x:name="helpcmdbinding" canexecute="althelpcanexecute" executed="althelpexecuted" command="{x:static local:topmenu.showhelp}" /> </usercontrol.commandbindings> <dockpanel>     <menu dockpanel.dock="top">         <menuitem header="_file">             <menuitem command="applicationcommands.new" />             <menuitem header="e_xit" inputgesturetext="alt+f4" />         </menuitem>         <menuitem header="_help">             <menuitem header="_view help" inputgesturetext="ctrl+f1" command="{x:static local:topmenu.showhelp}" />             <menuitem header="_about" />         </menuitem>     </menu> </dockpanel> 

topmenu.xaml.cs

    public partial class topmenu : usercontrol {     public static routedcommand showhelp = new routedcommand("althelp", typeof(topmenu));      public topmenu()     {         initializecomponent();     }       void newexecuted(object target, executedroutedeventargs e)     {         messagebox.show("the " + ((routedcommand)e.command).name + " command invoked on " + ((frameworkelement)target).name);     }     void newcanexecute(object sender, canexecuteroutedeventargs e)     {         e.canexecute = true;     }      void althelpexecuted(object target, executedroutedeventargs e)     {         messagebox.show("the " + ((routedcommand)e.command).name + " command invoked on " + ((frameworkelement)target).name);     }     void althelpcanexecute(object sender, canexecuteroutedeventargs e)     {         e.canexecute = true;     }   } 

home.xaml

<usercontrol x:class="samplewpfapp.home"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"           mc:ignorable="d"           d:designheight="300" d:designwidth="300"> <grid>     <textbox horizontalalignment="left" height="23" textwrapping="wrap" text="" verticalalignment="top" width="120" margin="10,37,0,0"/>     <textbox horizontalalignment="left" height="23" textwrapping="wrap" text="" verticalalignment="top" width="120" margin="10,86,0,0"/>     <button content="button" horizontalalignment="left" verticalalignment="top" width="75" margin="10,127,0,0"/> </grid> 

run application. make sure not click textbox or tab textbox. click file menu. menu enabled. check view menu. enabled. when click message boxes. good.

but when click textbox, menus disabled. can't menus enabled again until restart application , don't click textbox. (using gestures still fires messagebox though). can me identify issue? driving me crazy sometime :(

adding focusmanager.isfocusscope="true" topmenu usercontrol did trick.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -