-1

我正在使用此代码获取电子邮件文件夹列表:

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

我究竟做错了什么 ?

4

2 回答 2

1

如果您定义 的ItemTemplateListView您可以定义 ListViewItems 的外观。

在以下示例中,Title将仅显示属性的内容:

<ListView>
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Title}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

另一种方法是将ToString-method 的覆盖添加到emailFolder-class:

Class emailFolder
    Public Property Title As String

    Public Overrides Function ToString() As String
        Return Me.Title
    End Function
End Class
于 2018-02-07T13:02:07.920 回答
0

问题解决了。。谢谢大家的评论!!

只需覆盖ToString....Full 代码:

   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 
于 2018-02-07T12:54:33.090 回答