I have written the code shown below to serialize a string property in my custom activity. However, the property is not written to the XML file, when I call WorkflowMarkupSerializer.Serialize(). What am I missing
-----------
[Serializable]
[DesignerSerializer(typeof(PanedActivitySerializer), typeof(WorkflowMarkupSerializer))]
[Designer(typeof(PanedActivityDesigner), typeof(IDesigner))]
[Designer(typeof(PanedActivityDesigner), typeof(IRootDesigner))]
public class PanedActivity : System.Workflow.ComponentModel.Activity
{
public PanedActivity()
: base()
{
}
public PanedActivity(string predicate)
: base()
{
this.Predicate = predicate ;
}
public static DependencyProperty PredicateProperty =
System.Workflow.ComponentModel.DependencyProperty.Register(
"Predicate", typeof(string), typeof(PanedActivity));
public string Predicate
{
get
{
return ((string)(base.GetValue(PanedActivity.PredicateProperty)));
}
set
{
base.SetValue(PanedActivity.PredicateProperty, value);
}
}
}
public class PanedActivitySerializer : WorkflowMarkupSerializer
{
protected override bool CanSerializeToString(System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializationManager serializationManager, object value)
{
return true;
}
protected override string SerializeToString(System.Workflow.ComponentModel.Serialization.WorkflowMarkupSerializationManager serializationManager, object value)
{
List<PropertyInfo> props = new List<PropertyInfo>(base.GetProperties(serializationManager, value));
return props[0].GetValue(value, null).ToString();
}
protected override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
{
string predicate = value.ToString();
return new PanedActivity (predicate.ToString());
}
}
}

dependency properties do not get serialized
DragonC&#35;
Try re-writing your properties like this :
public
static DependencyProperty BodyProperty = System.Workflow.ComponentModel.DependencyProperty.Register("Body", typeof(string), typeof(SendMailActivity));[Description("Email body")]
[Category("EmailActivity")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string Body
{ get{ return ((string)(base.GetValue(SendMailActivity.BodyProperty))); }
set { base.SetValue(SendMailActivity.BodyProperty, value); } }
DesignerSerializationVisibility
Visible, Hidden, or Content
Determines how and if properties will be serialized.
Visible (the default) – the property will be serialized normally.
Hidden – prevents property serialization
Content – used for collection properties. The collection object itself is not serialized, however the contents of the collection are.
If a developer chooses a collection type, this property will be set to Content. If a developer chooses a non-serializable type, this property will be set to Hidden.
AridTag
Thanks for your help. I am using RC1. After adding the DesignerSerializationVisibility attribute, it worked.
Strange, that Vishal got the string property serialized without this attribute.
Al Harlow
Hi Mario,
I tried the following out with the PanedActivity and it worked as expected:
public class Program
{
public static void Main()
{
WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();
PanedActivity testActivity = new PanedActivity("Hello World");
FileStream fs = new FileStream(@"C:\Out.xml", FileMode.Create);
using(XmlTextWriter xmlWriter = new XmlTextWriter(fs, Encoding.Default))
{
markupSerializer.Serialize(xmlWriter, testActivity);
}
}
}
Out.xml:
<ns0:PanedActivity x:Name="PanedActivity" Predicate="Hello World" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:ActivityLibrary1;Assembly=ActivityLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
Are you trying something different and may I ask you what build number of Windows Workflow Foundation are you using