0

我在我的自定義序列活動中使用WorkflowItemsPresenter,並且想要禁用其中的活動的複製和粘貼。我發現了一些使用ICompositeView接口的解決方案,我試圖將它應用到WorkflowItemsPresenter,但它不起作用。有沒有人有任何想法如何禁用WorkflowItemsPresenter中的複製粘貼行爲?WF4禁用我的自定義序列中的WorkflowItemsPresenter中的複製粘貼

謝謝。

這裏是我的瘋狂代碼

BranchSequenceDesigner.xaml

<sap:ActivityDesigner x:Class="MyActivities.BranchSequenceDesigner" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation" 
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation" 
    > 
    <Canvas Name="ContentCanvas" Width="600" Height="600"/> 
    <sap:ActivityDesigner.Template> 
     <ControlTemplate > 
      <sap:WorkflowItemsPresenter Name="test" Items="{Binding Path=ModelItem.Children}"> 
       <sap:WorkflowItemsPresenter.SpacerTemplate> 
        <DataTemplate> 
         <Label HorizontalAlignment="Center" Content="Drop MyActivity Here !!!!!" FontStyle="Italic" Foreground="Red" /> 
        </DataTemplate> 
       </sap:WorkflowItemsPresenter.SpacerTemplate> 
      </sap:WorkflowItemsPresenter> 
     </ControlTemplate> 
    </sap:ActivityDesigner.Template> 

</sap:ActivityDesigner> 

BranchSequenceDesigner.xaml.cs

using System; 
using System.Collections.Generic; 
using System.Windows; 
using System.Activities.Presentation; 
using System.Activities.Presentation.Model; 
using System.Activities; 
using System.Activities.Presentation.Services; 

namespace MyActivities 
{ 
    public partial class BranchSequenceDesigner : ICompositeView 
    { 
     public BranchSequenceDesigner() 
     { 
      InitializeComponent(); 
     } 

     protected override void OnModelItemChanged(object newValue) 
     { 
      ModelItem canvasActivity = (ModelItem)newValue; 
      Update(canvasActivity); 
      canvasActivity.Properties["Children"].Collection.CollectionChanged += 
       new System.Collections.Specialized.NotifyCollectionChangedEventHandler 
        ((senders, args) => Update(this.ModelItem)); 
     } 

     void Update(ModelItem canvasActivity) 
     { 

      this.ContentCanvas.Children.Clear(); 
      foreach (ModelItem modelItem in canvasActivity.Properties["Children"].Collection) 
      { 
       var view = Context.Services.GetService<ViewService>().GetView(modelItem); 
       this.ContentCanvas.Children.Add((UIElement)view); 
       DragDropHelper.SetCompositeView((WorkflowViewElement)view, this); 
      } 
     } 

     protected override void OnPreviewDragEnter(DragEventArgs e) 
     { 
      if (DragDropHelper.AllowDrop(

        e.Data, 
        this.Context, 
        typeof(Activity))) 
      { 
       e.Effects = (DragDropEffects.Move & e.AllowedEffects); 
       e.Handled = true; 
      } 

      base.OnDragEnter(e); 
     } 

     protected override void OnPreviewDragOver(DragEventArgs e) 
     { 
      if (DragDropHelper.AllowDrop(

        e.Data, 
        this.Context, 
        typeof(Activity))) 
      { 
       e.Effects = (DragDropEffects.Move & e.AllowedEffects); 
       e.Handled = true; 
      } 

      base.OnDragOver(e); 
     } 

     protected override void OnPreviewDrop(DragEventArgs e) 
     { 
      ModelItem canvasActivity = this.ModelItem; 
      object droppedItem = DragDropHelper.GetDroppedObject(this, e, this.Context); 
      using (ModelEditingScope scope = canvasActivity.BeginEdit()) 
      { 
       ModelItem droppedModelItem = canvasActivity.Properties["Children"].Collection.Add(droppedItem); 
       scope.Complete(); 
      } 
      e.Handled = true; 
      DragDropHelper.SetDragDropCompletedEffects(e, DragDropEffects.Move); 
      base.OnDrop(e); 
     } 


     bool ICompositeView.CanPasteItems(List<object> itemsToPaste) 
     { 
      return false; 
     } 

     System.Activities.Presentation.View.TypeResolvingOptions ICompositeView.DroppingTypeResolvingOptions 
     { 
      get { throw new NotImplementedException(); } 
     } 

     bool ICompositeView.IsDefaultContainer 
     { 
      get { throw new NotImplementedException(); } 
     } 

     void ICompositeView.OnItemMoved(System.Activities.Presentation.Model.ModelItem modelItem) 
     { 
      throw new NotImplementedException(); 
     } 

     object ICompositeView.OnItemsCopied(List<System.Activities.Presentation.Model.ModelItem> itemsToCopy) 
     { 
      throw new NotImplementedException(); 
     } 

     object ICompositeView.OnItemsCut(List<System.Activities.Presentation.Model.ModelItem> itemsToCut) 
     { 
      throw new NotImplementedException(); 
     } 

     void ICompositeView.OnItemsDelete(List<System.Activities.Presentation.Model.ModelItem> itemsToDelete) 
     { 
     } 

     void ICompositeView.OnItemsPasted(List<object> itemsToPaste, List<object> metadata, Point pastePoint, WorkflowViewElement pastePointReference) 
     { 
      throw new NotImplementedException(); 
     } 
    } 
} 

BranchSequence.cs

using System.Activities; 
using System.Collections.ObjectModel; 
using System.ComponentModel; 
using System.Windows.Markup; 

namespace MyActivities 
{ 
    [Designer(typeof(BranchSequenceDesigner))] 
    [ContentProperty("Children")] 
    public sealed class BranchSequence : NativeActivity 
    { 
     [DefaultValue(null)] 
     private Collection<Activity> _children; 
     public Collection<Activity> Children { 
      get 
      { 
       return (_children = _children ?? new Collection<Activity>()); 
      } 
     } 

     protected override void Execute(NativeActivityContext context) {} 
    } 
} 

回答

1

我解決我的p通過使用DesignerView中的CommandBinding進行復制粘貼。 這是一個有用的link

using System.Activities.Presentation.View; 
using System.Windows; 
using System.Windows.Input; 

namespace MyActivities 
{ 
    public partial class BranchSequenceDesigner 
    { 
     public BranchSequenceDesigner() 
     { 
      InitializeComponent(); 
      this.Loaded += new RoutedEventHandler(this.BaseWorkflowDesigner_Loaded); 
     } 

     private void BaseWorkflowDesigner_Loaded(object sender, RoutedEventArgs e) 
     { 

      foreach (CommandBinding cb in this.Designer.CommandBindings) 
      { 
       if (cb.Command.Equals(ApplicationCommands.Delete)) 
       { 
        cb.CanExecute += new CanExecuteRoutedEventHandler(this.OnDeleteCommandCanExecute); 
       } 
       else if (cb.Command == DesignerView.CopyCommand) 
       { 
        cb.CanExecute += new CanExecuteRoutedEventHandler(this.OnCopyCommandCanExecute); 
       } 
       else if (cb.Command == DesignerView.PasteCommand) 
       { 
        cb.CanExecute += new CanExecuteRoutedEventHandler(this.OnPasteCommandCanExecute); 
       } 
       else if (cb.Command == DesignerView.CutCommand) 
       { 
        cb.CanExecute += new CanExecuteRoutedEventHandler(this.OnCutCommandCanExecute); 
       } 
      } 
     } 

     private void OnDeleteCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) 
     { 
      e.CanExecute = false; 
     } 

     private void OnCutCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) 
     { 
      e.CanExecute = false; 
     } 

     private void OnCopyCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) 
     { 
      e.CanExecute = false; 
     } 

     private void OnPasteCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) 
     { 
      e.CanExecute = false; 
     } 
    } 
} 
相關問題