Setting a default value for activity programatically

Oct 14, 2010 at 6:02 AM

Hi Trident Team,

I'm trying to write an activity where one of the inputs by default takes a value of 2. I have been told that using the PropertyMetadata to the dependency property definition would allow me to do this:

public static DependencyProperty eProperty =
	 DependencyProperty.Register("e", typeof(Int32), typeof(IntegerAdd),new PropertyMetadata(2));

However, it doesn't appear in Trident. Is there any way to do this?

 

Thanks,

David.

Oct 14, 2010 at 11:07 AM

Hi David,
 
Yes, you need to add PropertyMetadata to the dependency property definition to specify the default Input value.
 
Please find the below code snippet which achieves the same. Also this code snippet is taken from the default activity ChartDataTable which is shipped as part of trident. You can refer the activity code file present at location https://tridentworkflow.svn.codeplex.com/svn/Trident/Product/Activities/TridentChartActivities/ChartDataTable.cs.
 
public static System.Workflow.ComponentModel.DependencyProperty ChartTypeProperty =
System.Workflow.ComponentModel.DependencyProperty.Register("ChartType",
typeof(string), typeof(ChartDataTable), new System.Workflow.ComponentModel.PropertyMetadata("ColumnSeries"));
 
[OptionalInputParam]
[Name("Chart Type")]
[Description("The inital chart type. Possible values include: Bar Chart, Line Chart, Pie Chart, and many more.")]
public string ChartType
{
     get
       {
           return ((string)(base.GetValue(ChartDataTable.ChartTypeProperty)));
       }
     set
       {
           base.SetValue(ChartDataTable.ChartTypeProperty, value);
       }
}
 
Please make sure to use the DependencyProperty defined in System.Workflow.ComponentModel namespace.
 
If in case the above code snippet does not populate your default value in Trident. Can you please share the custom activity code that you have created to tridentp@microsoft.com and v-raaror@microsoft.com? 

Please let us know if this response solve your issues.
Regards,
Trident Support Team

Oct 15, 2010 at 12:42 AM

The DependencyProperty is defined in the correct namespace. The issue I found was that the input e is a required input parameter. When I set the parameter as optional, the default value is set as expected. Is there anyway to set a default value for a required input parameter?

Thanks,

David.

Oct 18, 2010 at 8:52 AM
Hi,
 
As part of the process we created a sample activity which has required input parameter and set default value for the parameter. After importing this activity to Trident. We were able to see the default value of the parameter in activity.
 
We have uploaded the sample activity code to CodePlex. You can download the code from teh following link MathematicalActivity.cs.
 
If you’re not able to set the default parameter of required parameter after going through the sample. Can you please share the sample which you have created? This will help us to analyze/solve the issue.
 
Please let us know if you have any further questions/concerns.
Thanks,
Trident Support Team
Oct 22, 2010 at 1:31 AM

Hi Thanks for the sample code. The reason I was unable to add the default value has to do with the order of the getter/setter and the dependency property definition. Here is my original code:

public static DependencyProperty aProperty�
	= DependencyProperty.Register("a", typeof(Int32), typeof(IntegerAdd),new PropertyMetadata(3));

[Name("a")]
[RequiredInputParam]
[DescriptionAttribute("")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public Int32 a
{
    get
    {
        return ((Int32)(base.GetValue(IntegerAdd.aProperty)));
    }
    set
    {
        base.SetValue(IntegerAdd.aProperty, value);
    }
}

This code would not set the dependency property default value for input parameters that were required (it did for optional inputs).
However, when this order is reversed, the default value is set as expected:

[Name("a")]
[RequiredInputParam]
[DescriptionAttribute("")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public Int32 a
{
    get
    {
        return ((Int32)(base.GetValue(IntegerAdd.aProperty)));
    }
    set
    {
        base.SetValue(IntegerAdd.aProperty, value);
    }
}
public static DependencyProperty aProperty
	= DependencyProperty.Register("a", typeof(Int32), typeof(IntegerAdd),new PropertyMetadata(3));

Is there any reason for this behaviour?
Thanks,
David Hehir



 

 

Oct 22, 2010 at 8:02 AM

Hi David,
 
We were not able to reproduce this issue on our Test machines with the code you have sent. We were able to add the default value irrespective of the order of the getter/setter and the dependency property definition.
 
Please let us know if this answers your questions.
Regards,
Trident Support Team

Oct 28, 2010 at 4:06 PM

Hi,

Can you please let us know if our response helped in answering your questions?

Thanks,
Trident Support Team

Oct 29, 2010 at 5:10 AM

yeah thanks, everything seems to be working fine now. 

Cheers,

David.