我在我的自定义序列活动中使用 WorkflowItemsPresenter,我想在那里禁用活动的复制和粘贴。我找到了一些使用 ICompositeView 接口的解决方案,我试图将其应用于 WorkflowItemsPresenter 但它不起作用。有谁知道如何在 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();
}
}
}
分支序列.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) {}
}
}