locked
Binding of a ExpressionTextBox-Column in a datagrid RRS feed

  • Question

  • Hi.

    Once again I face the same problem I always get from time to time. I always seem to mess up my expressiontextbox-bindings.
    Atm I use a collection of the following for my itemssource:

        public class DocumentDataItem
        {
            public string PlaceholderName { get; set; }
            public ModelItem PlaceholderValue { get; set; }
        }
    And my binding is the following:

    <DataGrid Name="dgData" 
                          AutoGenerateColumns="False" 
                          CanUserReorderColumns="False" 
                          Margin="5,5,5,0" 
                          SelectionUnit="FullRow"
                          Width="450"
                          Height="355">
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding Path=PlaceholderName, Mode=TwoWay}" Header="Placeholder" MinWidth="100" />
                        <DataGridTemplateColumn Header="Value to replace">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <sapv:ExpressionTextBox 
                                        Expression="{Binding Path=PlaceholderValue, Mode=TwoWay}" 
                                        ExpressionType="s:String"
                                        OwnerActivity="{Binding Path=ModelItem}" 
                                        LostFocus="ExpressionTextBox_LostFocus" 
                                        AcceptsReturn="False" 
                                        ExplicitCommit="True" 
                                        MinWidth="100" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>

    And I bind my itemssource in my code:

      dgData.ItemsSource = collectionCopy;

    My Textboxcolumn loads perfectly tho. The problem is that my that I can't "enter" my expressiontextbox, which is a problem I've faced before when messing up my bindings.

    Can anyone see where I go wrong here?

    Tuesday, March 16, 2010 7:53 AM

Answers

  • Hi Shounen,

    The ModelItem is essentially how the workflow designer get information about the underlying activities that it is representing.  for more info on model items, this link may be helpful: http://msdn.microsoft.com/en-us/library/ee662951(VS.100).aspx

    Since you are accessing the property from the property grid, you probably don't have direct access to the model item for your activity, but rather one of the activity's properties.  In this case, you'll probably have to make use of the ModelPropertyEntryToOwnerActivityConverter in the System.Activities.Presentation.Converters namespace.

    The following post may also be of some use to you in seeing how we can set up binding for the expression editor from the property grid.
    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/8a02341d-b24c-4cb3-a3bc-b08782f902bb/.  While they do not use a dialog, the underlying principle is the same.

    Hope this helps,
    Eric
    • Marked as answer by Shounen Friday, March 19, 2010 1:49 PM
    Wednesday, March 17, 2010 5:45 PM

All replies

  • While running in another project (a project with just the datagrid and a collection), I was able to get the following output.

    System.Windows.Data Error: 3 : Cannot find element that provides DataContext. BindingExpression:(no path); DataItem=null; target element is 'ContentPresenter' (Name=''); target property is 'Content' (type 'Object')


    Hope this helps you guys to find the problem.
    Tuesday, March 16, 2010 1:50 PM
  • Hi Shounen,

    Can you provide the custom activity code?  It does sound like an issue with your binding, but without the custom activity code, it's difficult to see what you are trying to bind your data grid to.

    Thanks,
    Eric
    Tuesday, March 16, 2010 5:21 PM
  • Hi Eric,

    My datagrid is actually running in a dialog, which is called by clicking on an elipsis in the property-menu. That's why I'm lacking a ModelItem I guess...
    What Is the ModelItem used for anyways?

    Can I just declare one as a property on my dialog and use that one, or should I get the ModelItem from the Workflow Activity?
    Wednesday, March 17, 2010 8:19 AM
  • Hi Shounen,

    The ModelItem is essentially how the workflow designer get information about the underlying activities that it is representing.  for more info on model items, this link may be helpful: http://msdn.microsoft.com/en-us/library/ee662951(VS.100).aspx

    Since you are accessing the property from the property grid, you probably don't have direct access to the model item for your activity, but rather one of the activity's properties.  In this case, you'll probably have to make use of the ModelPropertyEntryToOwnerActivityConverter in the System.Activities.Presentation.Converters namespace.

    The following post may also be of some use to you in seeing how we can set up binding for the expression editor from the property grid.
    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/8a02341d-b24c-4cb3-a3bc-b08782f902bb/.  While they do not use a dialog, the underlying principle is the same.

    Hope this helps,
    Eric
    • Marked as answer by Shounen Friday, March 19, 2010 1:49 PM
    Wednesday, March 17, 2010 5:45 PM
  • Thanks for your reply Eric.

    I'll try it out tomorrow and will let you know if it worked out.
    Wednesday, March 17, 2010 9:17 PM
  • This helped me push things in the right direction.
    I've changed my DocumentDataItem a bit tho, by adding a "OwnerActivity" attribute, which I set when I build my collection.

    Like that it seems to work. Altho, when I want to save my workflow now, I get the following error:

    System.Xaml.XamlObjectReaderException: Type 'System.Activities.Presentation.Model.ModelItemImpl' not visible. If the type is local, please set the LocalAssembly field in XamlReaderSettings.
       at System.Xaml.XamlObjectReader.SerializerContext.LocalAssemblyAwareGetXamlType(Type clrType)
       at System.Xaml.XamlObjectReader.ObjectMarkupInfo.ForObjectInternal(Object value, SerializerContext context, TypeConverter converter)
       at System.Xaml.XamlObjectReader.ObjectMarkupInfo.ForObject(Object value, SerializerContext context, TypeConverter instanceConverter, Boolean isRoot)

    Also, when I take a look in the XAML of my workflow, I notice this:

            <dwa:WordTemplateActivity DisplayName="Word Template Activity" Document="[document]" sap:VirtualizedContainerService.HintSize="344,130" TemplateLocation="Templates\WordTemplate">
              <dwa:WordTemplateActivity.DocumentData>
                <dwav:DocumentDataItem PlaceholderOwnerActivity="{x:Null}" PlaceholderValue="{x:Null}" PlaceholderName="test" />
                <dwav:DocumentDataItem PlaceholderOwnerActivity="{x:Null}" PlaceholderValue="{x:Null}" PlaceholderName="user" />
              </dwa:WordTemplateActivity.DocumentData>

    My PlaceholderOwnerActivity and PlaceholderValue are null, altho they should contain a value... It seems like my workflow can't write ModelItems into my XAML.
    Thursday, March 18, 2010 11:19 AM
  • Hi Shounen,

    I think I'm misunderstanding your scenario.  Is the following an accurate description of what you are trying to do?

    You want to create a custom activity with an argument of type Collection<DocumentDataItem>.  In the property grid, you've created your own custom control which opens a dialog containing a datagrid which is used to set the contents of the collection.

    If my understanding of your scenario is correct, you do not have to create instances of ModelItem anywhere in your code.  We should handle that for you. 

    I think seeing the code for your custom activity would greatly help me in understanding both the scenario and any issues you are encountering.  Would it be possible for you to provide me with this?

    Thanks,
    Eric
    Thursday, March 18, 2010 6:19 PM
  • That's indeed correct, only, the Collection<DocumentDataItem> is no Argument but a Variable.
    By setting my owner activity while building my collection, I was able to correctly activate the ExpressionTextBox. I can also edit the contents and add/delete rows.

    Only, when i want to save my workflow it gives me the error posted above.

    Is it possible to save ModelItems in my XAML, because I think that's where it goes wrong now...
    Due to the nature of my project I cannot post full codes here tho. I might be able to email it, if you would like to take a look at it.
    Thursday, March 18, 2010 8:50 PM
  • Hi Eric,

    I've kinda solved my problems. The OwnerActivity was the problem all along. Now I'm looking for a way to bind a string as an ExpressionTextBox.Expression.

    You can find my topic about it here: http://social.msdn.microsoft.com/Forums/en/wfprerelease/thread/a45ad6e8-c7a8-4b50-9631-793d550f0667

    Friday, March 19, 2010 1:50 PM