【发布时间】:2017-03-23 15:26:01
【问题描述】:
我有一个带有 StorageFile 元素的 listView(因为每个元素都代表 .mp3 文件)
<ListView x:Name="songList" HorizontalAlignment="Left" Height="680" Background="{Binding }" ItemsSource="{Binding ListOfStorageFiles , Mode=TwoWay , UpdateSourceTrigger=PropertyChanged}" Margin="986,120,0,-80" VerticalAlignment="Top" Width="294">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayName}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
到目前为止,我使用 folderPicker 从用户那里获取特定文件夹,并将所有文件作为 storageFiles 列表绑定到 listView。文件显示出来,我可以选择它们,但我必须在 listView SelectionChanged 上更改 mediaElement 源。不幸的是,当我将 SelectionChanged 添加到 listView 时,编译器告诉我 - Object reference not set to an instance of an object。任何人都知道是什么原因导致这种行为?这也是从列表播放媒体文件的正确方法(将 storageFile 绑定到列表)。
编辑:我可能必须为 EventName = "SelectionChanged" 使用 Interaction.Behaviors ?
【问题讨论】:
-
您能否将列表视图的
SelectedItem绑定到您的VM 上代表当前文件的属性?
标签: xaml uwp win-universal-app windows-10-universal