设计时间表示

时间:2012-09-26 15:17:19

标签: c# system.componentmodel

我有兴趣尝试让一个项目在设计时表现,不确定我能否实现我想要实现的目标。我构建了一个新的webpart,一个图表。此webpart有一个 ChartSettings ,它有许多可通过EditorPart配置的属性,并且在设置中有许多 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; }
}

图表的ChartSettings标记为Personalizable,因此它被序列化。这在网络上工作正常,设置是持久的,可以正确修改和恢复。但是,如果页面在另一个工具(如SharePoint设计器)中打开,则会因转换而开始出现错误。输出html看起来像是迷离:

<Chart myChartSettings="MyNamespace.ChartSettings"/>

MyNamespace.ChartSettings无法转换为ChartSettings的实例。这可以在属性上使用TypeConverters解决,并在转换器中使用诸如序列化之类的东西我可以生成:

<Chart myChartSettings="ConnectionString=A, QueryString=B, SeriesSettings={{Type=Bar, Theme=Daisy}, {Type=Line, Theme=Poppy}}" />

我真正希望在SharePoint设计器等工具中使用html实现的目的是:

<Chart>
   <ChartSettings ConnectionString="A" QueryString="B">
      <SeriesSettings Type="Bar" Theme="Daisy"/>
      <SeriesSettings Type="Line" Theme="Poppy"/>
   </ChartSettings>
</Chart>

有没有人知道这是否可能,如果是这样,如何实现这一目标我会遇到以下情况但不确定使用哪种,以及以何种组合方式实现我想要的并且是建议之后。< / p>

  • [的TypeConverter(typeof运算(ExpandableObjectConverter))]
  • [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  • [ContentProperty]

修改

我几乎设法到达那里:

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; }
}

这给了我:

<WpNs0:Chart>
   <Settings ConnectionString="testConnectionString" SelectQuery="testQuery">
      <Series Capacity="4"></Series>
   </Settings>
</WpNs0:Chart>

而不是

<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>

0 个答案:

没有答案