添加自定义数据源时出错

时间:2013-12-23 04:35:10

标签: vb.net xaml windows-phone-8 datasource

目前正在完成我正在制作的这个小应用程序,我遇到了这个小错误。我目前已经创建了自己的Listbox数据模板,并且我已将它们绑定,但是我收到一条错误消息,指出存在无效的强制转换异常。 我的绑定列表框模板是:

<DataTemplate x:Key="DataTemplate1">
    <Grid Height="59" Width="306">
        <TextBlock x:Name="Name" HorizontalAlignment="Left" Height="29" TextWrapping="Wrap" Text="{Binding Name}" VerticalAlignment="Top" Width="306"/>
        <TextBlock x:Name="Message" HorizontalAlignment="Left" Height="29" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="306" Margin="0,29,0,0"/>
    </Grid>
</DataTemplate>

vb代码是:

Dim myStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    Dim directory As String = "./PENCIL/Notes/*.*"
    Dim filenames As String() = Storage.GetFileNames(directory)
    Dim dataSource As New List(Of SampleData1)()
    dataSource.Add(New SampleData1() With {.Name = filenames(directory)})
    ItemsList.ItemsSource = dataSource

这基本上应该将文件加载到列表框中。

我的SampleData1是:

 Public Class SampleData1
    Private _name As String
    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(value As String)
            _name = value
        End Set
    End Property
End Class

我不断收到错误:

dataSource.Add(New SampleData1() With {.Name = filenames(directory)})

查看图片,以便更好地预览我不断获得的错误: http://puu.sh/5VGgj.png

有人能帮忙吗? 谢谢!

0 个答案:

没有答案