WPF ListView如何知道鼠标点击了哪一列 RT,现在需要对ListView上的内容进行过滤,操作员点击某行某列的内容,然后将该列不等于所点击的内容的行删除掉。请问如何知道鼠标点击的是第几列??麻烦大家帮帮忙!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用MVVM模式。在对应的ViewModel中定义一个类型是ICollectionView 的属性,然后绑定到ListView,就可以跟踪UI了。 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的source4. 要跟踪具体的行,使用EntityListView.CurrentItem这样UI的任何操作都可以跟踪,要做的是在OnEntityListViewChanged里实现你的逻辑。 对于列要麻烦些,因为要对任何列的控件定义相应的EventHandler,但原理应该是一致的,就是所有的控制是在ViewModel里,千万不要去codebehind。 ColumnClick事件, e.Column就是所击列的索引。 有关流媒体的问题 C# 调用远程机器上的COM对象 c# winfrom c++中的serverSocket控件在c#中对应的是哪个 自定义控件中如何捕获鼠标双击事件???100分 foreach ()怎么实现啊,有什么功能 拖动滚动条使图片平滑的滚动 请教一个问题,非常急,在线等 用C#如何检测我和系统是否装有“window优化大师”这这个应用程序? 我在一个项目中,任意一个form上添加一个imagelist,我想在整个项目的form上都可以引用,怎么实现呢? C#中怎样处理消息? 求指点一个简单的解码! 请教,如何使TextBox控件不输入小数并且不大于100
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里实现你的逻辑。