locked
Accessing the Activity behind the ActivityDesigner RRS feed

  • Question

  • I have a code activity, and a designer for the code activity.

    The designer defines one text box. Within the TextChanged event, I'd like to get access to the Activity itself so I can set some properties on it. Is that possible?


    Thanks

    Tuesday, May 18, 2010 12:30 AM

Answers

  • Hi,

    You can use ModelItem.Properties[PropertyName].SetValue(Value) to access the activity. Below is a simple example.

    Assume you have a property named "myText" of the activity. In activity designer, you have the textbox with "TextChanged" event, as  

    <TextBox Height="23" HorizontalAlignment="Left" Margin="54,27,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" TextChanged="textBox1_TextChanged" />

     

    Then, inside the event handler, set the "myText" property to a new value.

     

     

     private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
          this.ModelItem.Properties["myText"].SetValue("My value changed");
        }
    • Proposed as answer by Panda Wang Tuesday, May 18, 2010 10:46 AM
    • Marked as answer by Parry V Tuesday, May 18, 2010 3:51 PM
    Tuesday, May 18, 2010 10:42 AM

All replies

  • Yes. You can access the activity by using the ActivityDesigner.ModelItem property. The ModelItem is a wrapper around your activity which provides functionalities like change notification, undo, etc.
    Tuesday, May 18, 2010 3:01 AM
  • Hi,

    You can use ModelItem.Properties[PropertyName].SetValue(Value) to access the activity. Below is a simple example.

    Assume you have a property named "myText" of the activity. In activity designer, you have the textbox with "TextChanged" event, as  

    <TextBox Height="23" HorizontalAlignment="Left" Margin="54,27,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" TextChanged="textBox1_TextChanged" />

     

    Then, inside the event handler, set the "myText" property to a new value.

     

     

     private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
          this.ModelItem.Properties["myText"].SetValue("My value changed");
        }
    • Proposed as answer by Panda Wang Tuesday, May 18, 2010 10:46 AM
    • Marked as answer by Parry V Tuesday, May 18, 2010 3:51 PM
    Tuesday, May 18, 2010 10:42 AM
  • Thanks. That worked.
    Tuesday, May 18, 2010 3:51 PM