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);
}
}