.NET Framework Developer Center > .NET Development Forums > Windows Workflow Foundation > Dependency Property Returns Default value always
Ask a questionAsk a question
 

AnswerDependency Property Returns Default value always

  • Tuesday, November 03, 2009 10:43 AMVijay_Pandurangan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    I have used the dependency property in StateInitializtion Activity as follows

    1. 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 below

    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);
                }
            }
        }
    
    and in the if condition I have given as "this.customActivity1.MyCustomStatus.

    But it returned false alway.

    Thanks and regards,

    Vijay Pandurangan

Answers

  • Tuesday, November 03, 2009 6:48 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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/
  • Monday, November 09, 2009 1:49 AMAndrew_ZhuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

All Replies

  • Tuesday, November 03, 2009 6:48 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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/
  • Monday, November 09, 2009 1:49 AMAndrew_ZhuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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
  • Monday, November 09, 2009 5:59 AMVijay_Pandurangan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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