WF4 отключить копирование-вставку в WorkflowItemsPresenter в моей пользовательской последовательности

Я использую 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();
        }
    }
}

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 ответ

Я решил свою проблему с копировать-вставить с помощью CommandBinding из DesignerView. Вот полезная ссылка!

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;
        }
    }
}
Другие вопросы по тегам