locked
Collections in XAML RRS feed

  • Question

  • Hi,

    Is there a sample somewhere describing how to use collections in XAML?  The collections app in the Beta 1 samples is purely code based.  I'm just declaring a collections variable in a sequence activity and then dragging an AddToCollection activity into that sequence.  The IDE lets me bind the AddToCollection.Collection property to my sequence variable, but complains at runtime: System.InvalidOperationException: The property 'Collection' of 'AddToCollection`1' must be set.

    My XAML is below if it helps.  Thanks very much,

    - Erik

    <p:Activity mc:Ignorable="" x:Class="WorkflowConsoleApplication1.Sequence1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design" xmlns:__Sequence1="clr-namespace:WorkflowConsoleApplication1;" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
      <p:Sequence DisplayName="MySequence" sad:XamlDebuggerXmlReader.FileName="C:\Users\ejohnson\Documents\Visual Studio 10\Projects\TestAct\WorkflowConsoleApplication1\Sequence1.xaml">
    
        <p:Sequence.Variables>
    
          <p:Variable x:TypeArguments="s:Int32[]" Name="DataIn" />
    
        </p:Sequence.Variables>
    
        <p:AddToCollection x:TypeArguments="x:Int32" Item="[42]">[DataIn]</p:AddToCollection>
    
      </p:Sequence>
    
    </p:Activity>
    
    



    Erik Johnson
    • Edited by erikj Monday, June 8, 2009 6:13 PM Ugh. Typos
    Monday, June 8, 2009 6:10 PM

Answers

  • No, actually the problem is this -
    your variable isnt initialized. If you do, you'll get an error saying the array is of a fixed type.

    Try: List<int>

    <p:Activity mc:Ignorable="" x:Class="WorkflowConsoleApplication2.Sequence1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:w="clr-namespace:WorkflowConsoleApplication2;assembly=WorkflowConsoleApplication2" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

      <p:Sequence sad:XamlDebuggerXmlReader.FileName="C:\Users\kavitak\SharedwDesktop\Work\Beta1\Scratch\WorkflowConsoleApplication2\WorkflowConsoleApplication2\Sequence1.xaml">

        <p:Sequence.Variables>

          <p:Variable x:TypeArguments="x:Int32" Default="[2]" Name="test" />

          <p:Variable x:TypeArguments="scg:IList(x:Int32)" Default="[New List(Of Int32)]" Name="numbers" />

        </p:Sequence.Variables>

        <p:WriteLine>[test.ToString()]</p:WriteLine>

        <p:AddToCollection x:TypeArguments="x:Int32" Item="[12]">[numbers]</p:AddToCollection>

        <p:ForEach Values="[numbers]">

          <p:ActivityAction x:TypeArguments="s:Object">

            <p:ActivityAction.Argument>

              <p:Variable x:TypeArguments="s:Object" Name="item" />

            </p:ActivityAction.Argument>

            <p:WriteLine>[item.ToString()]</p:WriteLine>

          </p:ActivityAction>

        </p:ForEach>

      </p:Sequence>

    </p:Activity>

     

     


    Senior Lead Program Manager, Windows Workflow Foundation http://blogs.msdn.com/kavitak
    Monday, June 8, 2009 11:07 PM

All replies

  • Thanks for reporting the issue.
    Seems like a bug. Let me double check and get back to you.
    Kavita
    Senior Lead Program Manager, Windows Workflow Foundation http://blogs.msdn.com/kavitak
    Monday, June 8, 2009 6:52 PM
  • No, actually the problem is this -
    your variable isnt initialized. If you do, you'll get an error saying the array is of a fixed type.

    Try: List<int>

    <p:Activity mc:Ignorable="" x:Class="WorkflowConsoleApplication2.Sequence1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:w="clr-namespace:WorkflowConsoleApplication2;assembly=WorkflowConsoleApplication2" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

      <p:Sequence sad:XamlDebuggerXmlReader.FileName="C:\Users\kavitak\SharedwDesktop\Work\Beta1\Scratch\WorkflowConsoleApplication2\WorkflowConsoleApplication2\Sequence1.xaml">

        <p:Sequence.Variables>

          <p:Variable x:TypeArguments="x:Int32" Default="[2]" Name="test" />

          <p:Variable x:TypeArguments="scg:IList(x:Int32)" Default="[New List(Of Int32)]" Name="numbers" />

        </p:Sequence.Variables>

        <p:WriteLine>[test.ToString()]</p:WriteLine>

        <p:AddToCollection x:TypeArguments="x:Int32" Item="[12]">[numbers]</p:AddToCollection>

        <p:ForEach Values="[numbers]">

          <p:ActivityAction x:TypeArguments="s:Object">

            <p:ActivityAction.Argument>

              <p:Variable x:TypeArguments="s:Object" Name="item" />

            </p:ActivityAction.Argument>

            <p:WriteLine>[item.ToString()]</p:WriteLine>

          </p:ActivityAction>

        </p:ForEach>

      </p:Sequence>

    </p:Activity>

     

     


    Senior Lead Program Manager, Windows Workflow Foundation http://blogs.msdn.com/kavitak
    Monday, June 8, 2009 11:07 PM
  • we'll make the error message clearer in beta2.
    Senior Lead Program Manager, Windows Workflow Foundation http://blogs.msdn.com/kavitak
    Monday, June 8, 2009 11:11 PM
  • Thanks Kavita.  I knew if I saw a working example, it would clear things up. 

    The IDE is a little unhelpful because it shows a fixed-size array of T in the initial drop-down.  I wasn't sure if writing oput the fully-qualified name of List<> was the right thing to do. I'm sure that's going to get tuned up over time.


    Erik Johnson
    Monday, June 8, 2009 11:58 PM