Making the Visual Studio designer ignore a public property

前端 未结 4 2329
小蘑菇
小蘑菇 2021-02-13 19:48

I have a UserControl with a public property using the following attributes:

[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.H         


        
4条回答
  •  温柔的废话
    2021-02-13 20:47

    Making the property read only at design time will prevent it being serialized into the resx file. Strangely if MyType happens to be a collection the read only is ignored by the designer and you can still set the property at design time even though the property isn't written out into the resx so it's best to make the property not browsable too.

    [ReadOnly(true)]
    [Browsable(false)]
    public MyType MyProperty
    {
        get { return _MyProperty; }
        set { _MyProperty = value; }
    }
    

提交回复
热议问题