locked
DesignerView.AllowDrop does not work with StateMachine RRS feed

  • Question

  • I want to re-host the workflow designer in WPF. Most of my workflows will contain a StateMachine. I need to drag and drop customized States to the StateMachine of the current WorkflowDesigner.

    I managed to implement the drag and drop feature on the main Activity of the DesignerView but it does not work with the StateMachine. (When I drag a State onto the designer, it is added on the top of the designer but not on the place I clicked.)

    I would like the dragged State to be positionned where the click has been performed - and not somewhere else.

    Here is a snippet of my code:

    public MainWindow()

    {

           InitializeComponent();

           (new DesignerMetadata()).Register();

           toolboxControl = CreateToolbox();

           toolboxArea.Child = toolboxControl;

           InitializeDesigner();

          

    }

    private void InitializeDesigner()

    {

    //Load workflow designer

    (new DesignerMetadata()).Register();

    WorkflowDesigner workflowDesigner = new WorkflowDesigner();

    workflowDesigner.Load(workflowPath);

    //Get designer view

    System.Activities.Presentation.View.DesignerView designerView = workflowDesigner.Context.Services.GetService<System.Activities.Presentation.View.DesignerView>();

    designerView.AllowDrop = true;

    //Get StateMachine and states

    builderRoot = designerView.ActivitySchema as ModelItem;

    stateMachineModelItem = builderRoot.Properties["Implementation"].Value;

                           

    StateMachine computedValues = builderRoot.Content.ComputedValue as StateMachine;

    //Drag and Drop Handlers

    RadDragAndDropManager.Options.Effects = DragDropEffects.All;

    RadDragAndDropManager.AddDropQueryHandler(designerView, OnDropQuery);

    RadDragAndDropManager.AddDropInfoHandler(designerView, OnDropInfo);

    RadDragAndDropManager.SetAllowDrop(designerView, true);

    RadDragAndDropManager.SetAllowDrop(workflowDesigner.View, true);

    }

    private void OnDropQuery(object sender, DragDropQueryEventArgs e)

    {

          

    box = e.Options.Destination as DesignerView;

           builderRoot = box.ActivitySchema as ModelItem;

           stateMachineModelItem = builderRoot.Properties["Implementation"].Value;

           StateMachine computedValues = builderRoot.Content.ComputedValue as StateMachine;

          

    }

    private void OnDropInfo(object sender, DragDropEventArgs e)

    {

          

           AddState(activity);

          

    }

    private void AddState(Activity activity)

    {

           State state = new State()

           {

                 

           }

           stateMachineModelItem.Properties["States"].Collection.Add(state);

           SaveXamlFile();

    }

    <Window x:Class="RadWindowAsMainWindow.Window1" xmlns:local="clr-namespace:RadWindowAsMainWindow" …>

    <Window.DataContext>

    <local:IbisTasks />

    </Window.DataContext>

    <Window.Resources>

    <DataTemplate

                x:Key="ListBoxItemTemplate">

                <Grid>

                   

                </Grid>

           </DataTemplate>

    <Style

                TargetType="ListBoxItem">

                <Setter

                    Property="DragDropManager.AllowCapturedDrag"

                    Value="True" />

            </Style>

    </Window.Resources>

    <Grid>

                 

    <!—Toolbox for States-->

                  <telerik:RadListBox

                       x:Name="lbTaskList"

                       ItemsSource="{Binding IbisTaskList}" …                            

                  </telerik:RadListBox>

           </Grid>

    </Window>

    Thanks,

    Martine

    Thursday, October 11, 2012 12:24 PM

Answers

  • Basically positions are not working because you reimplemented drag+drop instead of leveraging state machine's built in drop handling.

    If you use a drag drop format that state machine understands, then state machine will handle the drop for you.

    Otherwise you have to do the work of working out the coordinates, and setting the correct attached view state  values (such as you can see in XAML).

    I would recommend using a data format that state machine understands. The data format is discussed a little here:

    http://blogs.msdn.com/b/tilovell/archive/2010/01/06/freeform-custom-activity-designers-using-icompositeview-part-4.aspx

    Tim

    • Marked as answer by LeoTang Friday, October 19, 2012 8:55 AM
    Thursday, October 11, 2012 8:16 PM