1

In Windows 7 e.CanExecute=false is disabling the contextmenu item. But in Windows Server2008R2 it is not working i.e the menu items get invisible(vanish). Why this is not working in Windows Server 2008R2? Is there an alternate to this?

-----Edited----------

Following is the code it is working fine in windows 7 but not in windows server 2008 r2 Below is code snippet :

XAML Code :

<ContextMenu x:Key="SharedContextMenu">
    <ContextMenu.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Cut" CanExecute="EnableContextMenu" Executed="ContextMenuCommandHandled" />
        <CommandBinding Command="ApplicationCommands.Copy" CanExecute="EnableContextMenu" Executed="ContextMenuCommandHandled" />
        <CommandBinding Command="ApplicationCommands.Paste" CanExecute="EnableContextMenu" Executed="ContextMenuCommandHandled" />
    </ContextMenu.CommandBindings>
    <MenuItem Command ="Cut" InputGestureText=" "/>
    <MenuItem Command ="Copy" InputGestureText=" "/>
    <MenuItem Command= "Paste" InputGestureText=" "/>
</ContextMenu>

Code behind :

private void EnableContextMenu(object sender, CanExecuteRoutedEventArgs e)
{
    try
    {
        ContextMenu controlContextMenu = sender as ContextMenu;
        if (controlContextMenu != null && controlContextMenu.PlacementTarget != null)
        {
            e.CanExecute = true;
            if (controlContextMenu.PlacementTarget is ComboBox)
            {
                if (string.IsNullOrEmpty(((ComboBox)controlContextMenu.PlacementTarget).Text))
                {
                    e.CanExecute = false;
                }
            }
        }
    }
    catch (Exception exceptionInstance)
    {
        LogManager.LogException("EnableContextMenu(): " + exceptionInstance.Message);
        MessageBox.Show(exceptionInstance.Message, Constants.SCREEN_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
    }
}
daniele3004
  • 13,072
  • 12
  • 67
  • 75
er.animesh
  • 49
  • 8
  • could you post the code where you set e.CanExecute = false . i'm guessing it is a routed command. YOU CAN NOT post question like this. that means nothing to no one. – eran otzap Sep 01 '14 at 19:29
  • I suspect the Style applied to the ContextMenu in Windows 2008 is different than the one applied in Windows 7. Something there is probably hiding the menu item, as shown in this question: http://stackoverflow.com/questions/3761672/wpf-how-to-hide-menu-item-if-commands-canexecute-is-false – CodeNaked Sep 02 '14 at 14:35
  • Yes the context menu style is also different in Win7 and win 2008. this might be the reason of this issue. Now How to resolve this? – er.animesh Sep 02 '14 at 15:27

0 Answers0