none
How to Bind ExpressionTextBox to my class object in ActivityDesigner?

    Question

  • Hello,

    I am just learning WF so this may be a easy question to answer.

    I have a custom code activity, AddJobToQueue that takes as input arguments a MessageQueue and a JobTicket. JobTicket is my custom class from a separate library (added as a Reference).

    In trying to create an custom activity designer for my activity, I have hit a snag. My activity designer uses two ExpressionTextBoxes for the two input arguments. I was able to get the binding correct for the MessageQueue, but I cannot determine how to get the binding for my custom class.

    My current XAML is this:

    <sap:ActivityDesigner x:Class="QueueActivityLibrary.AddJobToQueueDesigner"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:s="clr-namespace:System;assembly=mscorlib"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:sm="clr-namespace:System.Messaging;assembly=System.Messaging"
      xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
      xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation"
      xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
      <sap:ActivityDesigner.Resources>
        <ResourceDictionary>
          <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
        </ResourceDictionary>
      </sap:ActivityDesigner.Resources>
      <StackPanel>
        <TextBlock Text="Queue:" Margin="4" ToolTip="Queue to which the message is added">
        </TextBlock>
        <sapv:ExpressionTextBox
          Expression="{Binding Path=ModelItem.inputQueue, Mode=TwoWay,
          Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
          ExpressionType="sm:MessageQueue"
          OwnerActivity="{Binding Path=ModelItem}" HintText="MessageQueue object" />
        <TextBlock Text="Job Ticket Message Object:" Margin="4" ToolTip="JobTicket object">
        </TextBlock>
        <sapv:ExpressionTextBox
          Expression="{Binding Path=ModelItem.messageBody, Mode=TwoWay,
          Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
          ExpressionType="x:Type s:Object" 
          OwnerActivity="{Binding Path=ModelItem}" HintText="JobTicket object" />
      </StackPanel>
    </sap:ActivityDesigner>
    

    I tried adding my namespace to the list at the top but this was not correct.

     xmlns:pp="clr-namespace:Company.PNDocConv;assembly=Company.PNDocConv">
    

    Is there a way to set the ExpressionType to my class object? Any pointers on where I can find out what all of the XAML means? I've been searching on this for 2.5 hours and just getting lost.

    Thanks for any advise/pointers/help.

     

    Tuesday, October 19, 2010 5:08 PM

Answers

  • Hiya,

    I think you are saying that you are getting build errors involving the XAML

    xmlns:pp="clr-namespace:Company.PNDocConv;assembly=Company.PNDocConv"

    plus

    ExpressionType="pp:MyType"

    even though it looks like it should work. Anyway, I think it should work, but I assuming

    1) namespace and assembly name are correct
    2) the type MyType is public
    3) the type MyType is in a separate assembly

    Why the last requirement? Two reasons. One is that XAML namespaces are special cased for things in the same assembly, the assembly= part should be omitted. But two is that there are some compatibility issues between WF build task and other build tasks, and if your type depends on a WF build task, it may not be available at the time of WPF compilation (Known bug).

    [It may also work in the 'types are in same assembly' case by omitting ';assembly=x', if you don't have such build dependency issues.]

    +JIC, One last possible issue you could be hitting in a multi-assembly case is issues dealing with framework targeting, is having some assemblies that target .net client SKU which can't build because they depend on types in a full SKU assembly...

    If this doesn't help, please give a little more detail on the kind of problems you are having.

    Tim

    • Marked as answer by geekgrrl71 Thursday, October 21, 2010 7:46 PM
    Tuesday, October 19, 2010 8:27 PM
    Moderator

All replies

  • First of all, I'd test the rest of your code apart from binding to the custom class by using a String object and making sure that it's the class object that's causing the problem. Next, verify that your class object correctly implements a ToString() method- this may help.

    Failing that, I'm not sure if this will help, but there was a change in RTM made concerning passing custom types into an activity- this may be what's causing the problem in the designer. The workaround is to reference the custom typed object using a LambdaValue expression activity rather than accessing it directly- you might give this a try to see if it's what's causing the problem. See the following Wiki article concerning dereferencing input arguments via LambdaValue:

    http://social.technet.microsoft.com/wiki/contents/articles/using-reference-type-arguments-in-a-workflow-wf.aspx

    If none of this works, let me know and we'll investigate further.

    Tuesday, October 19, 2010 6:23 PM
    Moderator
  • Hiya,

    I think you are saying that you are getting build errors involving the XAML

    xmlns:pp="clr-namespace:Company.PNDocConv;assembly=Company.PNDocConv"

    plus

    ExpressionType="pp:MyType"

    even though it looks like it should work. Anyway, I think it should work, but I assuming

    1) namespace and assembly name are correct
    2) the type MyType is public
    3) the type MyType is in a separate assembly

    Why the last requirement? Two reasons. One is that XAML namespaces are special cased for things in the same assembly, the assembly= part should be omitted. But two is that there are some compatibility issues between WF build task and other build tasks, and if your type depends on a WF build task, it may not be available at the time of WPF compilation (Known bug).

    [It may also work in the 'types are in same assembly' case by omitting ';assembly=x', if you don't have such build dependency issues.]

    +JIC, One last possible issue you could be hitting in a multi-assembly case is issues dealing with framework targeting, is having some assemblies that target .net client SKU which can't build because they depend on types in a full SKU assembly...

    If this doesn't help, please give a little more detail on the kind of problems you are having.

    Tim

    • Marked as answer by geekgrrl71 Thursday, October 21, 2010 7:46 PM
    Tuesday, October 19, 2010 8:27 PM
    Moderator
  • Patrick and Tim,

    Thanks for replying.

    Patrick - I looked at the article you suggested but I'm afraid it was rather over my head at this point. I'm going to give it another read later.

    Tim - you are right in that I was getting build errors in the XAML when creating my custom activity designer component for my custom activity. All of the articles  I looked at showed how to bind the expression text box with simple types, such as Int32 and String. I managed to figure out how to bind the MessageQueue, but then got stuck on my custom class. I am new to

    My class is not in a separate assembly, it is a project in my solution. I realized that after I posted.

    I did finally get the designer component to work (i.e it doesn't thow errors) by binding my custom class object to a generic object:

    <sapv:ExpressionTextBox
          Expression="{Binding Path=ModelItem.messageBody, Mode=TwoWay,
          Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
          ExpressionType="s:Object" 
          OwnerActivity="{Binding Path=ModelItem}" HintText="JobTicket object" />
    

    Thanks again for the help.

    Sheri

    Wednesday, October 20, 2010 1:35 PM
  • I'm happy to hear you're unblocked. What I said about the separate assemblies is the same as for separate project files (it's the same thing). It sounds like you have separate project files, so I'm not sure what to recommend next.
    Tim
    Wednesday, October 20, 2010 4:28 PM
    Moderator