Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML WPF
Hi guys
 
I have a bit problem in menu commands, that trying exit from window with this XAML code:
<Menu>
    <MenuItem Header="_File">
        <MenuItem Header="a" />
        <Separator />
        <MenuItem Header="E_xit" InputGestureText="Alt+F4" Command="ApplicationCommands.Close" />
    </MenuItem>
</Menu>
But when click in File menu, the Exit item is disabled, what problem? May it's not bind to window? How to do this?
 
Thanks in advacneSmile | :)
Posted 29-Jul-12 7:23am
hzawary1.5K
Edited 29-Jul-12 9:27am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have you tried adding your own close method and calling that instead of sending a command ? Have you tried removing the InputGesture ? I don't know the answer, but it seems to me like some trial and error would help work it out.
  Permalink  
Comments
hzawary at 30-Jul-12 6:07am
   
When I use 'Command="ApplicationCommands.Close"' in 'MenuItem', this option disabled on running menu of window! May you test it?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I used this code in window XAML:
    <window.inputbindings>
        <keybinding command="NotACommand" modifiers="Alt" key="F4" />
        <keybinding command="Close" key="F2" />
    </window.inputbindings>
    <window.commandbindings>
        <commandbinding command="Close" executed="CommandBinding_Executed" />
    </window.commandbindings>
And this code in the menu:
<menu>
    <menuitem header="_File">
        <menuitem header="a" />
        <separator />
        <menuitem header="E_xit" inputgesturetext="F2" command="ApplicationCommands.Close" />
    </menuitem>
</menu>
Finally the problem is solved;)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 370
1 Gihan Liyanage 338
2 Vinay Mistry 160
3 ChauhanAjay 160
4 syed shanu 125
0 Sergey Alexandrovich Kryukov 9,021
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 30 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100