2016-02-15 68 views
0

我正在尝试为我的mediaplayer制作播放列表。我有一个列表,并需要获取它包含的名称,并将其设置到mainwindow上的列表框。我有代码,但它只是将项目设置为Windows.Storage.StorageFile。获取列表的属性<StorageFile>

PlaylistBox.ItemsSource = Playlist; 

upd。我有我的列表框WPF窗体上,我需要的

List<StorageFile>.DisplayName 

成员填补,但我只有对象Windows.Storage.StorageFile

+2

yura有什么问题?你无法绑定它? – pordi

+1

Yura你可以请添加更多的信息? – Alex

+0

MSDN是你的朋友https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile?cs-save-lang=1&cs-lang=csharp#code-snippet-1 – sll

回答

0

设置你的PlaylistBox的财产的DisplayMemberPath

<ListBox DisplayMemberPath="DisplayName" x:Name="PlaylistBox" /> 

或者你可以绑定到名字

PlaylistBox.ItemsSource = Playlist.Select(p=>p.DisplayName).ToList(); 

也可以指定ItemT名单emplate

<ListBox> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text={Binding DisplayName}/> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+0

谢谢,它的工作原理。我需要第二个。 –