locked
Disable Delete Activity (Both Delete & Cut) RRS feed

  • Question

  • Based on the following web-link, I have implemented my code and it is working good for DELETE.

    http://social.msdn.microsoft.com/Forums/zh-CN/wfprerelease/thread/26556475-93ff-4954-9635-471ba34a687e

    To disable DELETE . ..  now the user is NOT able to Delete activity using DELETE key using keyboard or using right-click context menu.

    To disable CUT ....... In the same way I implement it for CUT, it disables for pressing CTRL+X ..  . but NOT Disabling the right-click context menu on a given activity . . ..  Please suggest a way to disable CUT

    Here is the sample code that i have tried . . . . .

    <sap:ActivityDesigner.CommandBindings>
      <CommandBinding Command = "Cut" CanExecute = "CutCommand_CanExecute"/>
      <CommandBinding Command = "Delete" CanExecute = "DeleteCommand_CanExecute"/>
     </sap:ActivityDesigner.CommandBindings>
    
    private void DeleteCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
      {
       //MessageBox.Show("Can Execute Delete ..... ");
       e.ContinueRouting = false;
       e.CanExecute = false;
       e.Handled = true;
      }
      private void CutCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
      {
       //MessageBox.Show("Cut Can Execute . . . .. ");
       e.ContinueRouting = false;
       e.CanExecute = false;
       e.Handled = true;
      }
    
    Friday, November 19, 2010 5:50 AM

Answers

  • Hi Prabishmi,
    I'm not sure why its this way but it is just that you need to bind to a different command:

            <CommandBinding Command = "sapv:DesignerView.CutCommand" CanExecute="DesignerCutCommand_CanExecute" PreviewCanExecute="DesignerCutCommand_PreviewCanExecute" />

    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation

    Tim

    • Marked as answer by prabashmi Tuesday, November 23, 2010 5:52 AM
    Monday, November 22, 2010 5:31 PM

All replies

  • Hi Prabishmi,
    I'm not sure why its this way but it is just that you need to bind to a different command:

            <CommandBinding Command = "sapv:DesignerView.CutCommand" CanExecute="DesignerCutCommand_CanExecute" PreviewCanExecute="DesignerCutCommand_PreviewCanExecute" />

    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation

    Tim

    • Marked as answer by prabashmi Tuesday, November 23, 2010 5:52 AM
    Monday, November 22, 2010 5:31 PM
  • Thanks Tim,

    It perfectly works for me. I'm wondering how you guys are finding such solutions .. .  I could not think in this way at all.

     

    Tuesday, November 23, 2010 5:54 AM
  • Hi Prabishmi,
    I'm not sure why its this way but it is just that you need to bind to a different command:

            <CommandBinding Command = "sapv:DesignerView.CutCommand" CanExecute="DesignerCutCommand_CanExecute" PreviewCanExecute="DesignerCutCommand_PreviewCanExecute" />

    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation

    Tim



    Hi,

    I think most of the designer context menu commands are binding to the DesignerViewcommands (CutCommand, CopyCommand, etc), but there are some other commands like Delete and the Properties, they are using the ApplicationCommands (Delete, Properties). This is why you need to have different commands binding inside the Designer CommandBinding.

     

    e.g.

    <sap:ActivityDesigner.CommandBindings>
      <CommandBinding Command = "sapv:DesignerView.CutCommand" CanExecute = "CutCommand_CanExecute"/>
    <CommandBinding Command = "sapv:DesignerView.CopyCommand" CanExecute = "CopyCommand_CanExecute"/> <CommandBinding Command = "Delete" CanExecute = "DeleteCommand_CanExecute"/>
     <CommandBinding Command = "Properties" CanExecute = "PropertiesCommand_CanExecute"/>
    </sap:ActivityDesigner.CommandBindings>

     

     

    Tuesday, November 23, 2010 5:26 PM
  • I may be remembering wrong but I think I probably asked someone else the same question, a long time ago.
    Tim
    Tuesday, November 23, 2010 7:38 PM