2015-06-11 16 views
0

我已經使用下面的代碼將兩個屬性添加到窗體設計器,但它們不會顯示。字段類型與Sitecore.Form.Web.UI.Controls.CheckboxList類似,我需要它顯示相同的屬性。不幸的是,我不能進入這個代碼,模塊不會拋出任何錯誤,所以我覺得我錯過了一些簡單的東西。對於營銷人員(WFFM)的Web窗體自定義字段類型的視覺字段不顯示

public class CheckBoxListPipedField : Sitecore.Forms.Mvc.Models.Fields.CheckBoxListField 
{ 
    [VisualCategory("List")] 
    [VisualFieldType(typeof(Sitecore.Form.Core.Visual.ListField))] 
    [VisualProperty("Items:", 100)] 
    public ListItemCollection ListItems { get; set; } 
    [VisualCategory("List")] 
    [VisualFieldType(typeof(MultipleSelectedValueField))] 
    [VisualProperty("Selected Value:", 200)] 
    public ListItemCollection SelectedValue { get; set; } 

    public CheckBoxListPipedField(Item item) : base(item) 
    { 

    } 

    public override ControlResult GetResult() 
    { 
     var values = new List<string>(); 
     StringBuilder stringBuilder1 = new StringBuilder(); 
     if (this.Items != null) 
     { 
      foreach (SelectListItem selectListItem in 
       from item in this.Items 
       where item.Selected 
       select item) 
      { 
       values.Add(selectListItem.Value); 
       stringBuilder1.AppendFormat("{0}, ", selectListItem.Text); 
      } 
     } 
     var results = string.Join("|", values); 
     return new ControlResult(base.ID.ToString(), base.Title, results, stringBuilder1.ToString(0, (stringBuilder1.Length > 0 ? stringBuilder1.Length - 2 : 0))); 
    } 

} 
+1

您是否試過從'Sitecore.Form.Web.UI.Controls.CheckboxList'繼承而不是'Sitecore.Forms.Mvc.Models.Fields.CheckBoxListField' ?. –

回答

0

不知道爲什麼他們不會露面作爲CheckboxListField默認代碼沒有這些,但嘗試:

[TypeConverter(typeof(ListSelectItemsConverter))] 
public override List<SelectListItem> Items 
{ 
    get 
    { 
     return base.Items; 
    } 
    set 
    { 
     base.Items = value; 
     if (this.Items != null) 
     { 
      this.Value = (
       from x in this.Items 
       where x.Selected 
       select x.Value).ToList<string>(); 
     } 
    } 
} 

[ParameterName("selectedvalue")] 
[PropertyBinder(typeof(ListFieldValueBinder))] 
[TypeConverter(typeof(ListItemsConverter))] 
public override object Value 
{ 
    get; 
    set; 
} 

你也許能夠只設置這些來get { return base.Column },等等,但這裏是它在基類中的外觀。

[DefaultValue(1)] 
public int Columns 
{ 
    get; 
    set; 
} 

[TypeConverter(typeof(StringToDirection))] 
public Direction Direction 
{ 
    get; 
    set; 
} 

public int Rows 
{ 
    get 
    { 
     if (this.Items.IsNullOrEmpty<SelectListItem>()) 
     { 
      return 1; 
     } 
     int num = (this.Columns == 0 ? 1 : this.Columns); 
     if (this.Items.Count % num <= 0) 
     { 
      return this.Items.Count/num; 
     } 
     return this.Items.Count/num + 1; 
    } 
} 
0

有問題的代碼沒有錯。我忽略了將組件和類添加到新的字段類型,並且只設置了MVC類型。

相關問題