0

I'm working in a WPF project and I need one requirement. This is my main window:

http://img210.imageshack.us/img210/9752/rule.jpg

So, I want that when I drag and drop a custom activity (aggregate Functions), display his name in Compute TextBox... Is there some way to do it????

For example:

1) Drag and drop MaxActivity

2) Display in TextBox Compute: MaxActivity

3) Drag and drop SumActivity

4) Display in TextBox Compute: MaxActivity + SumActivity

5) Drag and Drop MaxActivity

6) Display in TextBox Compute: MaxActivity + SumActivity + MaxActivity1

Thanks a lot!

Xavi Guirao
  • 338
  • 4
  • 17
  • I would highly recommend starting with the code found on [Bea Stollnitz's blog here](http://bea.stollnitz.com/blog/?p=53) about dragging/dropping data bound items. I've implemented something like this in the past where users could drag/drop query "pieces" from one section of the application to another,and it would build a dynamic query out of them. – Rachel Jun 29 '12 at 16:21
  • @Rachel: This is a whole other beast. We're talking about Workflow 4, which adds a bunch of complexity on top of the WPF. –  Jun 29 '12 at 16:58
  • @Will Ah I missed the workflow tag, thanks :) – Rachel Jun 29 '12 at 17:14

1 Answers1

2
  1. I would strongly suggest you avoid this design, as however you end up implementing it will introduce brittleness to your code without any benefit (I can already see you are aggregating max and sums, why tell me again?)
  2. If you go ahead, get rid of that "Compute" TextBox. TextBoxes = enter text. You are just rephrasing what is already in the design surface. It makes no sense to allow me to change the text you generate. Use a TextBlock or Label.
  3. Do not, I repeat, not save this in your Activity. This is all UI tasks and should not be saving this information in your Activity configuration

If you have this

public sealed class MyActivity : Activity
{
    public string Compute {get;set;} // NO!

and this

<!-- NO! -->
<Label>Compute</Label><TextBox Text="{Binding ModelItem.Compute}"/>

you're probably doing this wrong.

So, how do you do it?

You can parse out your ModelItem and generate this string by listening to changes in the ModelItem and constructing this string every time. Note, your ModelItem will not be set when the constructor is called, so you are going to have to listen to changes to the ActivityDesigner.ModelItem property. There is no event for this, so you will have to know how to listen to changes in a DependencyProperty.

Once you are listening to changes in your ModelItem, whenever a change happens, you can walk down your ModelItem (which is hard) or just get the Activity from the ModelItem and examine it.

var child = ModelItem.Properties["Child"].Value.GetCurrentValue();
if(child == null)
    computeTextBox.Text = "Please add some computation stuff.";
else
    // hard stuff goes here...

Walking down the path from your Activity's child to whatever activities are held inside can be treacherous, as you can't assume your user has thrown in a Sequence rather than a single MaxActivity, or that they don't have seven nested Sequences, etc etc. So you have to have a pretty complex and brittle set of if else logic to try and parse out what is contained below. And if you start changing properties of the Activity tree outside of the ModelItem you're going to get out of sync with the UI.

Now, after reading that, go back to point 1. I listed in this answer and follow my advice. Drop the idea completely.

Community
  • 1
  • 1
  • I add these aggregate functions to make some querys in some arrays that I introduced as an arguments or variables – Xavi Guirao Jul 02 '12 at 09:01
  • Compute's Text Box: This Text Box contains the result of each activities after the workflow execution – Xavi Guirao Jul 02 '12 at 09:03
  • @XaviGuirao: Unfortunately, you appear to have a misunderstanding of how workflow works. You don't display the result of execution within the workflow's designer. –  Jul 02 '12 at 12:36
  • Ups sorry I'm confusing previously. I refer that in this text box I have all of the activities that previous execution, were added in the designer – Xavi Guirao Jul 02 '12 at 12:58