我尝试将默认值设置为Public Property
的图片UserControl
。我尝试用变量做到这一点,但我收到错误Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
Private Image_ As Image = My.Resources.MyImage
<Category("Appearance")> <DisplayName("Image")> <DefaultValue(Image_)> <Description("...")>
Public Property Image As Image
Get
Return NestedControl.Image
End Get
Set(ByVal value As Image)
NestedControl.Image = value
End Set
End Property
我还尝试设置默认值,例如<DefaultValue(GetType(Image), "My.Resources.MyImage")>
,但当我重置为UserControl
的属性时,它会变为&#34;无&#34; !!!
有什么想法吗?
答案 0 :(得分:1)
虽然+---------------+-------------------------+
| id|Last30daysOccurrenceCount|
+---------------+-------------------------+
|533ladk203ldpwk| 3|
|516dlksw9823adp| 1|
+---------------+-------------------------+
不支持此功能,但您可以使用旧式重置 PropertyName和 ShouldSerialize PropertyName方法来实现相同的功能。
Defining Default Values with the ShouldSerialize and Reset Methods中记录了这一点。
System.ComponentModel.DefaultValueAttribute