Binding read-only properties with Visual Studio Workflow Designer

If you declare a read-only property as defined by the two ways below, you cannot bind a property to it by using IDE (database icon is not available in this case):
1.

private static DependencyProperty TextToDisplayProperty =
DependencyProperty.Register("TextToDisplay", typeof(System.String), typeof(Activity1));

[Description("The text to output to the console")]
public string TextToDisplay
{
get { return (string)base.GetValue(Activity1.TextToDisplayProperty); }
}

2.

private static DependencyProperty TextToDisplayProperty =
DependencyProperty.Register("TextToDisplay", typeof(System.String), typeof(Activity1), new PropertyMetadata(DependencyPropertyOptions.ReadOnly));

[Description("The text to output to the console")]
public string TextToDisplay
{
get { return (string)base.GetValue(Activity1.TextToDisplayProperty); }
set { base.SetValue(Activity1.TextToDisplayProperty, value); }
}

Although there exists a crippled way to make it happen anyway here’s the statement of the Microsoft Product Group :

“General guidance is that read only properties should not be bound. The UI allows it due to the bug. In dev10 we will fix this and it should no longer be possible through the designer, but probably still possible in code. Please avoid using this pattern. We know it works, but it’s not supported or tested. Anyway, we will not disable it in code, since we now know someone has a dependency on it.”

Binding read-only properties with Visual Studio Workflow Designer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s