我有一個奇怪的問題編輯屬性網格中的類,其中屬性網格將不正確刷新。在.net中的類級別的RefreshProperties屬性,winforms +不正確地刷新屬性網格
我設法將問題簡化爲只有兩個屬性的類。我在最後包含了代碼以簡化解釋。
它基本上歸結爲具有兩個屬性的類。第一個是可擴展的(一種字體)。 該類本身是可擴展的,並且在類型轉換器中實現了CreateInstance方法。
要查看問題,請展開字體,編輯,說'加粗',然後轉到標籤頁。發生兩個問題:
(1)第二個屬性跳轉到最後一個擴展字體屬性。
(2)擴展字體的' - '符號變爲'+'。
問題通過將ResfreshProperties(RefreshProperties.All)附加到類中消失。
這很好,但我想了解它是如何解決問題的。我看了一下反射器,找不到在課堂級別上連接的任何RefreshProperties的例子。
///簡單的類
<TypeConverter(GetType(Class1Converter)), _
RefreshProperties(RefreshProperties.All)> _
Public Class Class1
Public Sub New(ByVal font As Font, ByVal image As Image)
Me.New()
Me.Image = image
Me.Font = font
End Sub
Public Sub New()
End Sub
Private _Font As Font = New Font("Arial", 10)
Public Property Font() As Font
Get
Return _Font
End Get
Set(ByVal value As Font)
_Font = value
End Set
End Property
Private _Image As Image
Public Property Image() As Image
Get
Return _Image
End Get
Set(ByVal value As Image)
_Image = value
End Set
End Property
End Class
///轉換爲類
Public Class Class1Converter
Inherits ExpandableObjectConverter
Public Overrides Function GetCreateInstanceSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
Public Overrides Function CreateInstance(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal propertyValues As System.Collections.IDictionary) As Object
Dim font As Font = TryCast(propertyValues("Font"), Font)
Dim image As Image = CType(propertyValues("Image"), Image)
Return New Class1(font, image)
End Function
End Class
/// A按鈕來承載類
Public Class MyButton
Inherits Button
Private _C As Class1 = New Class1
Public Property C() As Class1
Get
Return _C
End Get
Set(ByVal value As Class1)
_C = value
End Set
End Property
末級