无法使用 IMAPX 获取电子邮件文件夹名称
Can't get email folder names using IMAPX
我正在使用此代码获取电子邮件文件夹列表:
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
我做错了什么?
问题已解决..感谢大佬们的评论!!
只需覆盖 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
如果定义 ListView
的 ItemTemplate
,则可以定义 ListViewItems 的外观。
下面的例子只会显示 属性 Title
的内容:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
另一种方法是将 ToString
方法的覆盖添加到 emailFolder
-class:
Class emailFolder
Public Property Title As String
Public Overrides Function ToString() As String
Return Me.Title
End Function
End Class
我正在使用此代码获取电子邮件文件夹列表:
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
我做错了什么?
问题已解决..感谢大佬们的评论!!
只需覆盖 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
如果定义 ListView
的 ItemTemplate
,则可以定义 ListViewItems 的外观。
下面的例子只会显示 属性 Title
的内容:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
另一种方法是将 ToString
方法的覆盖添加到 emailFolder
-class:
Class emailFolder
Public Property Title As String
Public Overrides Function ToString() As String
Return Me.Title
End Function
End Class