WPF menu issue
-
lundi 6 août 2012 04:44
I Have menu on MainWindow.xaml file
<MenuItem Header="File">
<MenuItem Header="Save Job File" Command="ApplicationCommands.Save"/>
<MenuItem Header="Open Job File..." Command="ApplicationCommands.Open"/>
</MenuItem>In App.xaml.cs file I have this:
CommandManager.RegisterClassCommandBinding(typeof(MainWindow), new CommandBinding(ApplicationCommands.Open, Open, CanOpen));
CommandManager.RegisterClassCommandBinding(typeof(MainWindow), new CommandBinding(ApplicationCommands.Save, Save, CanSave));#region Open
private void Open(object sender, ExecutedRoutedEventArgs args)
{
ServiceLocator.Current.GetInstance<IJobFileService>().OpenJobFile();
}
private void CanOpen(object sender, CanExecuteRoutedEventArgs args)
{
args.CanExecute = true;
}
#endregion
#region Save
private void Save(object sender, ExecutedRoutedEventArgs args)
{
ServiceLocator.Current.GetInstance<IJobFileService>().SaveJobFile();
}
private void CanSave(object sender, CanExecuteRoutedEventArgs args)
{
// Can only save a job file when a label editor is selected
args.CanExecute = true;
}
#endregionI know that args.CanExcecute returns true for both menu but my menu items are still stays disable when Open a popup control and then try to open menu to save job file. my popup control is already getting closed when I click on menu. See Below
pls help.
thanks
Toutes les réponses
-
mardi 7 août 2012 04:19Modérateur
Hi Dee,
Please try to move the command content in App.cs into your mainwindow.cs.
If your issue still exist, please refer to below link for your reference:http://www.wpftutorial.net/RoutedCommandsInContextMenu.html
Hope it helps.
Have a nice day.
Annabella Luo[MSFT]
MSDN Community Support | Feedback to us
- Marqué comme réponse Annabella LuoModerator lundi 20 août 2012 04:41
-
lundi 20 août 2012 04:41Modérateur

