List of Lists item selection not working properly?

2019-08-03 15:24发布

in reference to my earlier question Binding List of Lists in XAML? i am facing a small issue. enter image description here

The above window has a ListView control where its each ListViewItem itself is another ListView. So the parent ListView consists of 8 (ListView)items, where each child item ListView consists of 1,1,1,2,1,2,1,2 items respectively. The below image has been taken when i am trying to click on the poster of 'Bug's Life'. However the selection is not updating the bottom two TextBlock controls which are bound to the ViewModel Movie property. It is still showing the 3 Idiots movie which was selected before. However if i click on the 27 Dresses poster it will update the Movie property. Please help me in identifying and solving this issue.

1条回答
做个烂人
2楼-- · 2019-08-03 16:10

In your ViewModel, you need to reset the SelectedItem for all the ListViews (by setting it to null) before assigning the new value like so:

private Movie m_SelectedMovie;

public Movie SelectedMovie
{
  get
  {
    return m_SelectedMovie;
  }
  set
  {
    if (m_SelectedMovie != value)
    {
      m_SelectedMovie = null;
      OnPropertyChanged("SelectedMovie"); // -> So the ListViews unselect everything
      m_SelectedMovie = value;
      OnPropertyChanged("SelectedMovie");
    }
  }
}
查看更多
登录 后发表回答