William Bartholomew

Musings on software engineering, technology and Aspergers Syndrome.

Setting Default Values for Workflow Dependency Properties

leave a comment »

When setting default values for dependency properties in Workflow Foundation there are two steps:

  1. Pass a PropertyMetadata object containing the default value to the DependencyProperty constructor (Line 8). This defaults the value of the property to the passed value.
  2. Apply the DefaultValue attribute to the property (Line 14). This provides the default value to the PropertyGrid which allows functionality such as the property appearing bold if the value is different to the default and the right-click Reset option to set the property back to the default. 

For example:

   1:  Private Const DefaultPort As Integer = 25
   2:   
   3:  Public Shared PortProperty As DependencyProperty = _
   4:      DependencyProperty.Register( _
   5:          "Port", _
   6:          GetType(Integer), _
   7:          GetType(SendEmail), _
   8:          New PropertyMetadata(DefaultPort) _
   9:      )
  10:   
  11:  <Description("Port")> _
  12:  <Category("Input")> _
  13:  <Browsable(True)> _
  14:  <DefaultValue(DefaultPort)> _
  15:  <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
  16:  Public Property Port() As Integer
  17:      Get
  18:          Return (CType((MyBase.GetValue(SendEmail.PortProperty)), Integer))
  19:      End Get
  20:      Set(ByVal Value As Integer)
  21:          MyBase.SetValue(SendEmail.PortProperty, Value)
  22:      End Set
  23:  End Property

Written by wbarthol

September 17, 2008 at 3:33 pm

Posted in dotnet, programming

Leave a Reply