首页 文章

listVIew SelectionChanged和StorageFiles

提问于
浏览
0

我有一个带有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从用户获取特定文件夹,并将所有文件绑定到listView作为storageFiles列表 . 文件显示并且我能够选择它们,但我必须在listView SelectionChanged 上更改mediaElement Source . 不幸的是,当我将SelectionChanged添加到listView时,编译器会告诉我 - Object reference not set to an instance of an object . 有谁知道是什么导致这种行为?这也是从列表中播放媒体文件的正确方法(将storageFile绑定到列表) .

编辑:我可能必须使用Interaction.Behaviors的EventName =“SelectionChanged”?

1 回答

  • 1

    我结束了

    <interactivity:Interaction.Behaviors>
                <core:EventTriggerBehavior EventName="SelectionChanged">
                    <core:InvokeCommandAction Command="{Binding OnSelectedSongFromList }" CommandParameter="{Binding ElementName=songList, Mode=TwoWay}"></core:InvokeCommandAction>
    
                           </core:EventTriggerBehavior>
                </interactivity:Interaction.Behaviors>
    

    然后在VM中我使用列表:

    ListOfMedia.MoveTo((uint)asf.SelectedIndex);
    

相关问题