清单项目选择清单不正常? [英] List of Lists item selection not working properly?

查看:114
本文介绍了清单项目选择清单不正常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提到我先前的问题绑定列表的列表在XAML?我面临的一个小问题。

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

上面的窗口中有一个ListView控件,其中其各项ListViewItem的本身是另一个ListView控件。因此,家长的ListView由8个(ListView控件)项目,其中每个子项的ListView分别由1,1,1,2,1,2,1,2项。下面的图片已经采取,当我试图点击虫虫特工队的海报。然而,选择不更新其绑定到视图模型的电影的属性下方的两个TextBlock的控制。它仍然显示这是前所选择的三个傻瓜电影。但是,如果我在的 27连衣裙点击的海报,将更新的电影的属性。请帮我识别并解决这个问题。

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.

推荐答案

在你的视图模型,你需要重新设置的SelectedItem 所有的ListView S(通过设置它)之前分配,像这样的新值:

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");
    }
  }
}

这篇关于清单项目选择清单不正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆