.NET Framework Developer Center >
.NET Development Forums
>
Windows Workflow Foundation
>
Dependency Property Returns Default value always
Dependency Property Returns Default value always
- Hi,I have used the dependency property in StateInitializtion Activity as follows1. CustomActivity (contains a dependency property of type bool, which will be set during the execution of this activity)2. An if-else activity which executes if the above dependecy propery is value is true.But regardless of any value set to the dependency property the value returned is always false. I have provided the code of custom activity belowand in the if condition I have given as "this.customActivity1.MyCustomStatus.
public partial class MyCustomActivity : System.Workflow.ComponentModel.Activity { private static DependencyProperty MyCustomStatusProperty = DependencyProperty.RegisterAttached("MyCustomStatus", typeof(bool), typeof(MyCustomActivity)); private bool _asStatus; public MyCustomActivity() { InitializeComponent(); } protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { var executionStatus = base.Execute(executionContext); var result = true;// <based on db operation bool value will be set SetValue(MyCustomStatusProperty, result; _asStatus = result; return executionStatus; } public bool MyCustomStatus { get { var dpValue = (bool)GetValue(MyCustomStatusProperty); return dpValue ; } set { SetValue(MyCustomStatusProperty, value); } } }
But it returned false alway.Thanks and regards,
Vijay Pandurangan
Answers
- This is because of activity execution context: http://msdn.microsoft.com/en-us/magazine/cc163414.aspx
That should give you what you need. An easy work around is to add a variable to your WF base class and then copy the value to the base class first and in your conditional code you can simply do
this.BaseClassVariable =! false
If my response answers your question, please mark it as the "Answer" by clicking that button above my post.
My blog: http://www.RyanVice.net/- Proposed As Answer byGeert van Horrik Wednesday, November 04, 2009 9:01 AM
- Marked As Answer byVijay_Pandurangan Monday, November 09, 2009 6:00 AM
- Hi,Vijay
-"copy the value to the base class first "
You can copy the value to parent class by:
this.Parent.GetActivityByName("MyCustomActivity").MyCustomStatus=MyCustomStatus;
Regards
This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support- Marked As Answer byVijay_Pandurangan Monday, November 09, 2009 6:00 AM
All Replies
- This is because of activity execution context: http://msdn.microsoft.com/en-us/magazine/cc163414.aspx
That should give you what you need. An easy work around is to add a variable to your WF base class and then copy the value to the base class first and in your conditional code you can simply do
this.BaseClassVariable =! false
If my response answers your question, please mark it as the "Answer" by clicking that button above my post.
My blog: http://www.RyanVice.net/- Proposed As Answer byGeert van Horrik Wednesday, November 04, 2009 9:01 AM
- Marked As Answer byVijay_Pandurangan Monday, November 09, 2009 6:00 AM
- Hi,Vijay
-"copy the value to the base class first "
You can copy the value to parent class by:
this.Parent.GetActivityByName("MyCustomActivity").MyCustomStatus=MyCustomStatus;
Regards
This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support- Marked As Answer byVijay_Pandurangan Monday, November 09, 2009 6:00 AM
Hi Ryan and Andrew,
Thanks for you reply.
In my situation, the custome activity can go to any where in the workflow
as
Main Workflow -> (State-> Stateinitialization Or Event Drive Activity Or Some other Custome Composite Activity)
And the property will be accessed by another custom/built in activity which may in the same tree of in some other tree of activities, and hence to acces the parent (Main Workflow) I may need to loop/traverse through the activities.
So I acheived this with a Activity Bind property from the Main Workflow.
Thanks for your replies.
Thanks and Regards,
Vijay Pandurangan


