This is the structure of the XAML:
<controls:MasterDetailsView
ItemsSource="{x:Bind Artists}">
<controls:MasterDetailsView.MasterHeader>
// Some Code
</controls:MasterDetailsView.MasterHeader>
<controls:MasterDetailsView.ItemTemplate>
// Some Code
</controls:MasterDetailsView.ItemTemplate>
<controls:MasterDetailsView.DetailsTemplate>
<DataTemplate x:DataType="data:ArtistView">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<RelativePanel HorizontalAlignment="Stretch">
// Some Code
</RelativePanel>
<ListView
x:Name="AlbumsListView"
Grid.Row="1"
HorizontalAlignment="Stretch"
ItemsSource="{x:Bind Albums}"
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:AlbumView">
<Grid Margin="10,0,0,30">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<RelativePanel>
// Some Code
</RelativePanel>
<ListView
x:Name="SongsListView"
Grid.Row="1"
HorizontalAlignment="Stretch"
ContainerContentChanging="SongsListView_ContainerContentChanging"
IsItemClickEnabled="True"
ItemClick="SongsListView_ItemClick"
ItemsSource="{x:Bind Songs}"
SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Music">
// Some Code
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</DataTemplate>
</controls:MasterDetailsView.DetailsTemplate>
</controls:MasterDetailsView>
I am trying to highlight an item of SongsListView
(it's inside another listview) whose music is playing by changing the foreground. I implemented it in the ContainerContentChanging but the foreground will only be changed after reload the page. I want it to be updated in real time. How can I do that?
I registered a MusicSwitching event which will take place when the current playing music is changed, so that I can set the foreground of the item that has been played to black, and the foreground of the item to be played to a highlight color.
public async void MusicSwitching(Music current, Music next)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
var item = ArtistMasterDetailsView.Items.First((a) => (a as ArtistView).Name == next.Artist);
var container = ArtistMasterDetailsView.ContainerFromItem(item);
});
}
I can first find the item correctly, but the container is null. Why? I thought it is the DataTemplate that contains the item.