正在实现一个功能:播放器正在播放的歌曲会在对应的歌曲列表头显示一个图标,就像这样:
datatemplate代码:
<DataTemplate x:Key="Local_GroupingSongDataTemplate">
。。。
<Path Width="40" Visibility="{Binding}"
Data="{StaticResource VolumeIcon}"
>
<Path.DataContext>
<MultiBinding Converter="{StaticResource VolumeIconConverter}" UpdateSourceTrigger="PropertyChanged">
<Binding />
<Binding Path="CurrentSong" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}"/>
</MultiBinding>
</Path.DataContext>。。。
listbox代码:
<ListBox x:Name="SpreadList" DataContext={Binding}
ItemsSource="{Binding LocalMusicCollection}"
ItemTemplate="{DynamicResource Local_GroupingSongDataTemplate}" 。。。
LocalMusicCollection和CurrentSong是ViewModel的属性。现在问题就是path里面绑定不到CurrentSong这个属性,显示DependencyProperty.UnsetValue