![](/img/trans.png)
[英]How to Get SelectedItem as DataTemplate in Listview?
[英]Binding SelectedItem of ListView inside of DataTemplate
我目前正在開發音樂播放器應用程序,但始終無法在應用程序的所有ListView中突出顯示播放曲目。
例如,有一個包含唱片列表的頁面,每個頁面都包含一個帶有歌曲列表的 DataTemplate。 當您第一次選擇它並將所選項目綁定到視圖模型時,一切都很好。 但是在離開該頁面並返回到該頁面時,viewmodel保留了有關正在播放哪個sing的信息, 但綁定不會使該項目突出顯示 。
這是我的XAML:
<ListView x:Name="lstSongs"
ItemsSource="{Binding attachments}"
SelectionChanged="lstSongs_SelectionChanged"
ScrollViewer.VerticalScrollMode="Disabled"
SelectedValue="{Binding DataContext.selectedSong, ElementName=Group_Page}"
SelectedItem="{Binding DataContext.selectedSong, ElementName=Group_Page}"
ItemContainerStyle="{StaticResource ListViewTextHighlight}"
Grid.Row="1">
綁定SelectedItem和SelectedValue只是為了看看任何一個都可以工作。
我可能缺少明顯的東西,但是我希望有人能幫助我。
謝謝!
我認為SelectedItem
綁定需要為Mode=TwoWay
SelectedItem="{Binding DataContext.selectedSong, ElementName=Group_Page, Mode=TwoWay }"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.