locked
A simple workflow view elements that counts RRS feed

  • Question

  • Hi i would like to create a simple view element that counts, is this possible?

    I can't seen to bind the Count property

    using System;
    using System.Activities;
    using System.Activities.Statements;
    using System.Activities.Validation;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    
    namespace MyActivities
    {
      [Designer(typeof(CounterDesigner))]
      public class Counter : CodeActivity
      {
        
        public int Count { get; set; }
    
        protected override void Execute(CodeActivityContext context)
        {
          Count += 1;
        }
      }
    }
    


    and the designer

    <sap:WorkflowViewElement x:Class=MyActivities.CounterDesigner"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation">
      <Grid>
        <Border Width="20" Height="20" BorderBrush="Black" BorderThickness="1">
          <TextBlock x:Name="txtCounter" Text="{Binding Path=ModelItem.Count, Mode=OneWay, FallbackValue=0}" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>      
        </Border>
      </Grid>
    </sap:WorkflowViewElement>
    
    

    Thanks very much,

    Friday, August 19, 2011 3:07 PM

Answers

  • Consider binding to an argument in your CounterDesigner, the example below uses a bool, but the idea is the same with your int.

     public InArgument<bool> Argument{ get; set; }

    Create a Type Converter class for the InArgument:


      object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                bool checkBoxIsChecked = false;
                ModelItem modelItem = value as ModelItem;
                if (value != null)
                {
                    InArgument<bool> inArgument = modelItem.GetCurrentValue() as InArgument<bool>;
                    if (inArgument != null)
                    {
                        if (inArgument.Expression is Literal<bool>)
                        {
                            Literal<bool> boolExpression = inArgument.Expression as Literal<bool>;
                            checkBoxIsChecked = boolExpression.Value;
                        }
                        //add handling for more expression subclasses here...
                    }
                }
                return checkBoxIsChecked;
            }

            object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                InArgument<bool> inArgument = new InArgument<bool>((bool)value);
                return inArgument;
            }

     

    Then in your xaml, bind using the TypeConverter.

     

            <CheckBox Grid.Row="0" Margin="3" x:Name="executeCheckBox" IsChecked="{Binding Path=ModelItem.Argument, Mode=TwoWay,
                Converter={StaticResource checkboxToArgumentConverter}}">Execute Sequence?</CheckBox>

     

    If that doesn't help, do a bit of googling, the approach is documented,

     


    - jeremiah adams
    • Marked as answer by Andrew_Zhu Monday, August 29, 2011 6:26 AM
    Friday, August 19, 2011 11:28 PM