我一直在制作控件并为(CustomClass)列表添加了一个属性。自定义类包含一个字符串、一个图像和一个包含字符串和图像的另一个自定义类的列表。我已经通过添加可浏览属性将此属性添加到设计器中,并且所有似乎都可以正常工作。
我的问题是在运行程序时出现的。我可以设置属性中的所有值,然后我可以返回它们并保存它们,但是,一旦我运行程序,这些值就会被清除,因为属性设置为 Nothing。
为了允许编辑和保存我的属性,我意识到我必须初始化列表并且已经在属性的访问器方法中完成了(如果属性的值是空的)。
我已经修改了设计器中的值,并在使用该属性的所有项目及其基础字段以及该属性的方法本身上放置了一个断点。第一个断点命中是它被访问并且值总是什么都没有。
我不确定应该将值存储在哪里,因为我已经检查了设计器代码,它通常会存储字符串等类型,并且我已经检查了资源以查看它们是否已保存在那里(就像图像一样) . 运行代码后,设计器中的值也会被清除。
控件内的一些代码
Private _Items As List(Of Models.Category) = New List(Of Models.Category)
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Data"), _
Description("The items with sub items that should be displayed"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Property Items As List(Of Models.Category)
Get
'Return _Items
Return Me.ExpMenu1.Categories
End Get
Set(ByVal value As List(Of Models.Category))
Me.ExpMenu1.Categories = value
'_Items = value
End Set
End Property
ExpMenu1 中的违规代码
''' <summary>
''' Gets or sets the categories.
''' </summary>
''' <value>The categories.</value>
Public Property Categories() As List(Of Category)
Get
If m_Categories Is Nothing Then
m_Categories = New List(Of Category)
End If
Return m_Categories
End Get
Set(ByVal value As List(Of Category))
m_Categories = value
End Set
End Property
顶级班(类别)
Imports System.Collections.Generic
Namespace ExpandingMenuWPF.Models
''' <summary>
''' Category class.
''' </summary>
Public Class Category
''' <summary>
''' Gets or sets the name of the category.
''' </summary>
''' <value>The name of the category.</value>
Public Property CategoryName() As String
Get
Return _CategoryName
End Get
Set(ByVal value As String)
_CategoryName = value
End Set
End Property
Private _CategoryName As String
''' <summary>
''' Gets or sets the sub items.
''' </summary>
''' <value>The Sub Items.</value>
Public Property SubItems() As List(Of SubItem)
Get
Return _SubItems
End Get
Set(ByVal value As List(Of SubItem))
_SubItems = value
End Set
End Property
Private _SubItems As New List(Of SubItem)
Private _ShowImage As Boolean
Public Property ShowImage() As Boolean
Get
Return _ShowImage
End Get
Set(ByVal value As Boolean)
_ShowImage = value
End Set
End Property
Private _Image As Image
Public Property CategoryImage() As Image
Get
Return _Image
End Get
Set(ByVal value As Image)
_Image = value
End Set
End Property
End Class
End Namespace
嵌套类(子项)
Namespace ExpandingMenuWPF.Models
''' <summary>
''' Sub Item class.
''' </summary>
Public Class SubItem
Public Sub New()
End Sub
''' <summary>
''' Gets or sets the title.
''' </summary>
''' <value>The title.</value>
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal value As String)
_Title = value
End Set
End Property
Private _Title As String
Private _ShowImage As Boolean
Public Property ShowImage() As Boolean
Get
Return _ShowImage
End Get
Set(ByVal value As Boolean)
_ShowImage = value
End Set
End Property
Private _Image As Image
Public Property SubItemImage() As Image
Get
Return _Image
End Get
Set(ByVal value As Image)
_Image = value
End Set
End Property
End Class
End Namespace
如果有人对应该将值存储在哪里有任何想法或知识,我将不胜感激。我不认为我在做任何特别复杂的事情。
Resx 文件。部分项目数据:
<data name="ExpandingVerticalMenu1.Items" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAEdFeHBhbmRpbmdNZW51V1BGLCBWZXJzaW9uPTEuMC4wLjAsIEN1
bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAwDAAAAUVN5c3RlbS5EcmF3aW5nLCBWZXJz
aW9uPTQuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49YjAzZjVmN2YxMWQ1MGEz
YQUBAAAAIEV4cGFuZGluZ01lbnVXUEYuTW9kZWxzLkNhdGVnb3J5BAAAAA1fQ2F0ZWdvcnlOYW1lCV9T
dWJJdGVtcwpfU2hvd0ltYWdlBl9Jb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