Click here to Skip to main content
Rate this: bad
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:
    <MenuItem Header="_File">
        <MenuItem Header="a" />
        <Separator />
        <MenuItem Header="E_xit" InputGestureText="Alt+F4" Command="ApplicationCommands.Close" />
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 8:23am
Edited 29-Jul-12 10:27am
Rate this: bad
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.
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
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 Peter Leow 160
1 Mika Wendelius 156
2 Abhinav S 155
3 Sergey Alexandrovich Kryukov 115
4 TheRealSteveJudge 114
0 Sergey Alexandrovich Kryukov 8,593
1 OriginalGriff 6,536
2 Peter Leow 3,727
3 Zoltán Zörgő 3,436
4 Richard MacCutchan 2,417

Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 30 Jul 2012
Copyright © CodeProject, 1999-2015
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