RT,现在需要对ListView上的内容进行过滤,操作员点击某行某列的内容,然后将该列不等于所点击的内容的行删除掉。请问如何知道鼠标点击的是第几列??麻烦大家帮帮忙!!

解决方案 »

  1.   

    使用MVVM模式。在对应的ViewModel中定义一个类型是ICollectionView 的属性,然后绑定到ListView,就可以跟踪UI了。 
      

  2.   


    public class ProductViewModel
    {
        private IProductModel _model;
        public ICollectionView EntityListView { get; private set; }    [ImportingConstructor]
        public ProductViewModel(IProductModel model)
        {
            this._model = model;
            EntityListView = CollectionViewSource.GetDefaultView(_model.GetProducts());        if (EntityListView != null)
            {
                EntityListView.CurrentChanged += OnEntityListViewChanged;
            }
        }    private void OnEntityListViewChanged(object sender, EventArgs e)
        {
            // TODO: add your code here
        }
    }
    1. EntityListView 要定义成只读
    2. 邦定EventHandlerOnEntityListViewChanged 到 CurrentChanged 
    3. 邦定EntityListView 到WPF Listcontrol的source
    4. 要跟踪具体的行,使用EntityListView.CurrentItem
    这样UI的任何操作都可以跟踪,要做的是在OnEntityListViewChanged里实现你的逻辑。
      

  3.   

    对于列要麻烦些,因为要对任何列的控件定义相应的EventHandler,但原理应该是一致的,就是所有的控制是在ViewModel里,千万不要去codebehind。
      

  4.   

    ColumnClick事件, e.Column就是所击列的索引。