WF4在我的自定义序列中的WorkFlowItemspresenter中禁用复制纸



我正在使用自定义序列活动中的WorkFlowItemspresenter,我想禁用那里的活动的复制和粘贴。我找到了一些使用ICompositeView接口的解决方案,并且试图将其应用于Workflowitemspresenter,但它不起作用。有人有什么想法如何禁用工作流程中的复制糊状行为?

谢谢。

这是我的疯狂代码

branchSequendedesigner.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>

branchSequendedesigner.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) {}
    }
}

i通过使用DesignErtiew的命令键入解决了我的问题。这是一个有用的链接!

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

相关内容

  • 没有找到相关文章

最新更新