我正在使用此代码获取电子邮件文件夹列表:
Class emailFolder
Public Property Title As String
End Class
Public Shared Function GetFolders() As List(Of emailFolder)
Dim folder = New List(Of emailFolder)
Dim foldername = client.Folders
For Each parentFolder In foldername
Dim parentPath = parentFolder.Path
If parentFolder.HasChildren Then
Dim subfolders = parentFolder.SubFolders
For Each subfolder In subfolders
Dim subPath = subfolder.Path
folder.Add(New emailFolder With {.Title = parentFolder.Name})
Next
End If
Next
Return folder
End Function
Public sub btn_click handles Button1.click
ListView.ItemSource=GetFolders
我不知道我的代码有什么问题,但我在ListView
中得到的项目(顺便说一下,我在wpf中)看起来像这样:
MyApplication++emailfolder
MyApplication++emailfolder
MyApplication++emailfolder
MyApplication++emailfolder
我做错了什么?
答案 0 :(得分:1)
如果您定义ListView
的{{3}},则可以定义ListViewItems的外观。
使用以下示例,只会显示属性Title
的内容:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
另一种方法是将ToString
- 方法的覆盖添加到emailFolder
- 类:
Class emailFolder
Public Property Title As String
Public Overrides Function ToString() As String
Return Me.Title
End Function
End Class
答案 1 :(得分:0)
问题解决了。谢谢评论家伙!!
只需覆盖ToString
....完整代码:
Class emailFolder
Public Property Title As String
Public Overrides Function ToString() As String
Return Me.Title
End Function
End Class
Public Shared Function GetFolders() As List(Of emailFolder)
Dim folder = New List(Of emailFolder)
Dim foldername = client.Folders
For Each parentFolder In foldername
Dim parentPath = parentFolder.Path
If parentFolder.HasChildren Then
Dim subfolders = parentFolder.SubFolders
For Each subfolder In subfolders
Dim subPath = subfolder.Path
folder.Add(New emailFolder With {.Title = parentFolder.Name})
Next
End If
Next
Return folder
End Function
Public sub btn_click handles Button1.click
ListView.ItemSource=GetFolders