WF4 Binding - This newbie to WF4 needs some serious help! RRS feed

  • Question

  • I can't bind a combobox to an observablevariable. This newbie to WF4 needs help. I've been able to bind every other way but this.


    using System;
    using System.Activities;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Text;
    using System.Windows.Data;
    using System.Windows.Markup;

    namespace CommercialWorkflowActivity
        public sealed class ComboBoxCode : NativeActivity
            public InArgument<string> Text { get; set; }

            protected override void Execute(NativeActivityContext context)
                Text = "This is the Text";
                //string text = text = context.GetValue(this.Text);


            //**** Start: Add variables on startup ****//
            public ComboBoxCode()

            public void InstantiateVariables()
                for (Int32 i = 1; i <= 5; i++)
                    Variable<string> lTestVar = new Variable<string>();
                    lTestVar.Name = "TestVar" + i;


            ObservableCollection<Variable> variables;
            public ObservableCollection<Variable> Variables
                    if (this.variables == null)
                        variables = new ObservableCollection<Variable>();
                    return variables;
            //**** End: Add variables on startup ****//



    <sap:ActivityDesigner x:Class="CommercialWorkflowActivity.ComboBoxDesigner"
        xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="100" d:DesignWidth="200">
                <c:ComboBoxItemConverter x:Key="comboBoxItemConverter"/>
            <ComboBox Height="23" HorizontalAlignment="Left" Margin="36,12,0,0" VerticalAlignment="Top" Width="120"
                      ItemsSource="{Binding Path=Variables}" />

    Wednesday, October 26, 2011 5:12 PM


All replies

  • Make your ItemsSource = "{Binding Path=ModelItem.Variables}"
    Wednesday, October 26, 2011 11:02 PM
  • Thank you for the reply. When I set it to; ItemsSource = "{Binding Path=ModelItem.Variables}" I receive an ArgumentNullException as shown below.

    Thursday, October 27, 2011 12:45 PM
  • Sorry, I don't think the screen clip displayed so here it is.

    Thursday, October 27, 2011 12:46 PM
  • That's progress, at least now your binding ;-)


    As a WAG(Wild Assed Guess) I would suggest that you have null items in your collection somehow, or that the collection itself is null.  There is really no way for me to do more than guess given the amount of information that I have.

    Thursday, October 27, 2011 1:09 PM
  • Thank you for your response. Now at least I can move forward.
    Thursday, October 27, 2011 1:12 PM
  • Hi Robert,
    ComboBox will do a call to ICollection.IndexOf(null) during initialization which indirectly causes the assert. The more immediate problem causing the assert is that ModelItemCollection throws ArgumentNullException for IndexOf(null). This is a known bug in .Net 4. I have worked around it in the past, discussed at the end of this post:



    • Marked as answer by GoldenChair Friday, October 28, 2011 8:33 PM
    Thursday, October 27, 2011 10:36 PM
  • Tim,

    Thank you for your help. Your example helped us out and we got the combobox to bind.


    Friday, October 28, 2011 8:35 PM