Xaml listVIew选择更改和存储文件
我有一个包含StorageFile元素的列表视图,每个元素代表.mp3文件Xaml listVIew选择更改和存储文件,xaml,uwp,win-universal-app,windows-10-universal,Xaml,Uwp,Win Universal App,Windows 10 Universal,我有一个包含StorageFile元素的列表视图,每个元素代表.mp3文件 <ListView x:Name="songList" HorizontalAlignment="Left" Height="680" Background="{Binding }" ItemsSource="{Binding ListOfStorageFiles , Mode=TwoWay , UpdateSourceTrigger=PropertyChanged}" Margin="986,120,0,-
<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。文件显示出来,我可以选择它们,但我必须在listView选择Changed时更改mediaElement源。不幸的是,当我将SelectionChanged添加到listView时,编译器告诉我-Object引用未设置为对象的实例。有人知道这种行为的原因吗?这也是从列表播放媒体文件的正确方法—将存储文件绑定到列表
编辑:我可能必须使用交互。EventName=SelectionChanged的行为?我最终的结果是
<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>
能否将列表视图的SelectedItem绑定到VM上表示当前文件的属性?
ListOfMedia.MoveTo((uint)asf.SelectedIndex);