1

我有兴趣尝试让一个项目在设计时表现出来,但不确定我是否能实现我想要实现的目标。我已经构建了一个新的 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; }
}

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

有谁知道这是否可能,如果可以,如何实现这一点我遇到了以下问题,但不确定使用哪个,以及以什么组合来实现我想要的和我想要的建议。

  • [TypeConverter(typeof(ExpandableObjectConverter))]
  • [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  • [内容属性]

编辑

我几乎设法到达那里:

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

0 回答 0