【问题标题】:listVIew SelectionChanged and StorageFiles列表查看 SelectionChanged 和 StorageFiles
【发布时间】: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


【解决方案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>

然后在虚拟机中我使用列表来:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    相关资源
    最近更新 更多