locked
XAML workflow definition - setting values of collection property

    Question

  • Hi,

    I have a custom activity
    MyStateMachineWorkflowActivity (inherits from StateMachineWorkflowActivity) that owns a collection property MyDictionary of type IDictionary (structure: key = string, object = ArrayList (or similar) of strings).

    public partial class MyStateMachineWorkflowActivity : StateMachineWorkflowActivity
    {
        private IDictionary _myDictionary;

        [Browsable(false)]
        public IDictionary MyDictionary
        {
            get { return _
    myDictionary; }
            set { _
    myDictionary= value; }
        }
               
        public EncodaStateMachineWorkflowActivity()
        {
            InitializeComponent();

            _
    myDictionary= new Hashtable();
        }
    }



    Now I'd like to fill this property with values using the XAML definition of the workflow:


    <MyStateMachineWorkflowActivity x:Class="Workflow1" Name="Workflow1" InitialStateName="Workflow1InitialState"
        xmlns="clr-namespace:Test.Workflow.Activities;Assembly=Test.Workflow.Activities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
        xmlns:wf="http://schemas.microsoft.com/winfx/2006/xaml/workflow"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:collections="clr-namespace:System.Collections;Assembly=System, Version=2.0.0.0"
        xmlns:system="clr-namespace:System;Assembly=System, Version=2.0.0.0" >

        <
    MyStateMachineWorkflowActivity.MyDictionary>
            <collections:ArrayList x:key="Key1">
                <system:String>Item1</system:String>
                <system:String>Item2</system:String>
            </
    collections:ArrayList>
            <collections:ArrayList x:key="Key2">
                <system:String>Item3</system:String>
                <system:String>Item4</system:String>
            </
    collections:ArrayList>
        </
    MyStateMachineWorkflowActivity.MyDictionary>

        <wf:StateActivity Name="Workflow1InitialState" />

    </
    MyStateMachineWorkflowActivity>


    How does this declaration has to be adapted that the workflow will be compiled and run correctly?

    Thanks in advance!

    Tuesday, February 06, 2007 2:24 PM

Answers

  • You need to make two changes.  First, update the collections and system xmlns to the following since the assembly they are in is mscorlib and not system:

     

    xmlns:collections="clr-namespace:System.Collections;Assembly=mscorlib, Version=2.0.0.0"

    xmlns:system="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0"

     

    Second, you need to use the following serialization for you MyDictionary property:

     

    <MyStateMachineWorkflowActivity.MyDictionary>

      <collections:Hashtable>

        <collections:ArrayList>

          <x:Key>

            <system:String>Key1</system:String>

          </x:Key>

          <system:String>Item1</system:String>

          <system:String>Item2</system:String>

        </collections:ArrayList>

        <collections:ArrayList>

          <x:Key>

            <system:String>Key2</system:String>

          </x:Key>

          <system:String>Item3</system:String>

          <system:String>Item4</system:String>

        </collections:ArrayList>

      </collections:Hashtable>

    </MyStateMachineWorkflowActivity.MyDictionary>

    Wednesday, February 07, 2007 7:57 AM

All replies

  • It has been a while since i have been in the details of WF but...

    My first thought is i remember having to use a DependencyProperty to get xoml serialization. Look at some of the custom activity examples that are using them, change your property to a DependencyProperty, and see if it works.

    If not you may be suffering from a limitation that i know generics have, not sure about dictionaries.

    see this post for details on that http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=631198&SiteID=1

    hope this helps,

    steve

    Tuesday, February 06, 2007 4:45 PM
  • slein,

    Try to replace the HashTable object by WorkflowParameterBindingCollection class to enable initializing a collection within the xoml file.

    Have a look at the following thread:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1009208&SiteID=1

     

    Thanks

    Roman

    Wednesday, February 07, 2007 3:53 AM
  • You need to make two changes.  First, update the collections and system xmlns to the following since the assembly they are in is mscorlib and not system:

     

    xmlns:collections="clr-namespace:System.Collections;Assembly=mscorlib, Version=2.0.0.0"

    xmlns:system="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0"

     

    Second, you need to use the following serialization for you MyDictionary property:

     

    <MyStateMachineWorkflowActivity.MyDictionary>

      <collections:Hashtable>

        <collections:ArrayList>

          <x:Key>

            <system:String>Key1</system:String>

          </x:Key>

          <system:String>Item1</system:String>

          <system:String>Item2</system:String>

        </collections:ArrayList>

        <collections:ArrayList>

          <x:Key>

            <system:String>Key2</system:String>

          </x:Key>

          <system:String>Item3</system:String>

          <system:String>Item4</system:String>

        </collections:ArrayList>

      </collections:Hashtable>

    </MyStateMachineWorkflowActivity.MyDictionary>

    Wednesday, February 07, 2007 7:57 AM