I'm interested in trying to get an item to behave at design time, not sure if I can achieve what I want to achieve. I've constructed a new webpart, a chart. This webpart has a single ChartSettings which has a number of properties on configurable via an EditorPart and within the settings has a number of SeriesSettings.
public class Chart : WebPart
{
[Personalizable(Shared)]
public ChartSettings Settings { get; set; }
}
public class ChartSettings
{
public String ConnectionString { get; set; }
public String QueryString { get; set; }
public List<SeriesSettings> { get; }
}
public class SeriesSettings
{
public ChartType Type { get; set; }
public String Theme { get; set; }
}
The Chart has the ChartSettings marked as Personalizable so it is serialized. This works fine on the web, settings are persisted and can be modified and restored correctly. If however the page is opened within another tool such as SharePoint designer errors start to occur due to conversion. The output html would look vaguley like:
<Chart myChartSettings="MyNamespace.ChartSettings"/>
MyNamespace.ChartSettings can't be converted to an instance of a ChartSettings. This can be worked around with TypeConverters on the property, and using something such as serialization within the converter I could produce:
<Chart myChartSettings="ConnectionString=A, QueryString=B, SeriesSettings={{Type=Bar, Theme=Daisy}, {Type=Line, Theme=Poppy}}" />
What I really want to achieve in the html in a tool such as SharePoint designer however is:
<Chart>
<ChartSettings ConnectionString="A" QueryString="B">
<SeriesSettings Type="Bar" Theme="Daisy"/>
<SeriesSettings Type="Line" Theme="Poppy"/>
</ChartSettings>
</Chart>
Does anyone know if this is possible, and if so how to go about achieving this I've come across the following but not sure which to use, and in what combination to achieve exactly what I want and am after suggestions.
- [TypeConverter(typeof(ExpandableObjectConverter))]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- [ContentProperty]
EDIT
I've almost managed to get there with:
public class Chart : WebPart
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ChartSettings Settings { get; set; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class ChartSettings
{
public String ConnectionString { get; set; }
public String QueryString { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<SeriesSettings> { get; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class SeriesSettings
{
public ChartType Type { get; set; }
public String Theme { get; set; }
}
This gives me:
<WpNs0:Chart>
<Settings ConnectionString="testConnectionString" SelectQuery="testQuery">
<Series Capacity="4"></Series>
</Settings>
</WpNs0:Chart>
rather than
<WpNs0:Chart>
<Settings ConnectionString="testConnectionString" SelectQuery="testQuery">
<Series>
<SeriesSettings Theme="default" Type="Bar"/>
<SeriesSettings Theme="default" Type="Area"/>
<SeriesSettings Theme="default" Type="Spline"/>
</Series>
</Settings>
</WpNs0:Chart>