在一次使用WPF ListView的时候,我发现在MVVM模式下在ListView开启虚拟化的情况下,将ListViewItem的IsSelected属性与一个对应的布尔值进行双向绑定。
文档目录结构如下:
源码如下:
NotifyBase.cs
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace WpfApp10
{
public class NotifyBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void DoNotify([CallerMemberName]string name = "")
{
// 提醒界面更新绑定的属性
PropertyChanged?.Invoke(name, new PropertyChangedEventArgs(name));
}
}
}
MainViewModel.cs(还另外包含一个Demo类型与ListViewItem进行数据绑定)
using System.Collections.ObjectModel;
namespace WpfApp10
{
public class MainViewModel : NotifyBase
{
priva