我创建了一个具有多个属性的自定义控件。我为自定义控件添加了一些可扩展属性。现在,我希望该用户可以编辑属性网格中的可扩展属性字段以及为其相关属性设置的新输入值。我在属性网格扩张属性“需要登录”,并有两个子属性如下:如何在属性网格中编辑可扩展属性的字段?
前景色
可见
我设置的两个子属性的值“Required Sign”可扩展属性到“Required Sign”属性的字段,如下图所示:
绿箱:“需要登录”可扩展属性
蓝箱:在“需要登录”两个子属性扩展属性
红盒子:在“需要登录”领域展开式属性
但是,我无法直接更改或编辑“必需的标志”展开属性的字段值。如何更改或编辑可扩展属性的字段值(图中的红色框)?
我的代码如下:
[DisplayName("Label Information")]
[Description("Label Informationnnnnnnnnnnnnnnn")]
[DefaultProperty("Text")]
[DesignerCategory("Component")]
[TypeConverter(typeof(AllFloorsContentsLabelInformationTypeConverter))]
public class AllFloorsContentsLabelInformation : LabelX
{
private AllFloorsContentsLabelRequiredSignInformation allFloorsContentsLabelRequiredSignInformation = new AllFloorsContentsLabelRequiredSignInformation();
public AllFloorsContentsLabelInformation()
{
}
[Category("Data")]
[DisplayName("Required Sign")]
[Description("Required Signnnnnnnnnnnnnnn")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public AllFloorsContentsLabelRequiredSignInformation AllFloorsContentsLabelRequiredSignInfo
{
get
{
return allFloorsContentsLabelRequiredSignInformation;
}
}
}
[DisplayName("Required Sign Information")]
[Description("Required Sign Informationnnnnnnnnnnnnnnn")]
[DefaultProperty("Text")]
[DesignerCategory("Component")]
[TypeConverter(typeof(AllFloorsContentsLabelRequiredSignInformationTypeConverter))]
public class AllFloorsContentsLabelRequiredSignInformation
{
private Color foreColor = Color.Red;
private ConfirmationAnswers visible = ConfirmationAnswers.Yes;
public AllFloorsContentsLabelRequiredSignInformation()
{
}
[Category("Appearance")]
[DisplayName("ForeColor")]
[Description("ForeColor")]
[DefaultValue(typeof(Color), "Red")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new Color ForeColor
{
get
{
return foreColor;
}
set
{
foreColor = value;
}
}
[Category("Behavior")]
[DisplayName("Visible")]
[Description("Visibleeeeeeeeeeeeeeeeee")]
[DefaultValue(ConfirmationAnswers.Yes)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ConfirmationAnswers Visible
{
get
{
return visible;
}
set
{
visible = value;
}
}
}
public class AllFloorsContentsLabelRequiredSignInformationTypeConverter : ExpandableObjectConverter//TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(AllFloorsContentsLabelRequiredSignInformation))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(String) && value is AllFloorsContentsLabelRequiredSignInformation)
{
AllFloorsContentsLabelRequiredSignInformation allFloorsContentsLabelRequiredSignInformation = (AllFloorsContentsLabelRequiredSignInformation)value;
return allFloorsContentsLabelRequiredSignInformation.ForeColor.ToString() + "; " + allFloorsContentsLabelRequiredSignInformation.Visible.ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
AllFloorsContentsLabelRequiredSignInformation allFloorsContentsLabelRequiredSignInformation = new AllFloorsContentsLabelRequiredSignInformation();
string strExtractData = (string)value;
Color clrForeColor = Color.FromName(strExtractData.Substring(0, strExtractData.IndexOf(";") - 1).Trim());
string strVisible = strExtractData.Substring(strExtractData.IndexOf(";") + 1, strExtractData.Length).Trim();
allFloorsContentsLabelRequiredSignInformation.ForeColor = clrForeColor;
if (strVisible == "Yes")
{
allFloorsContentsLabelRequiredSignInformation.Visible = ConfirmationAnswers.Yes;
}
else
{
allFloorsContentsLabelRequiredSignInformation.Visible = ConfirmationAnswers.No;
}
return allFloorsContentsLabelRequiredSignInformation;
}
return base.ConvertFrom(context, culture, value);
}
}
你可以编辑集合编辑器的其他属性吗? – LightStriker
嗨马克安德烈Jutras。是的,我可以编辑其他属性的字段,除了我的可扩展属性(必填标志)的字段外。 – MRS1367