OnPropertyChanged 无法按预期使用 ObjectListView

OnPropertyChanged not working as expected with ObjectListView

这是我的模型class,我对这个问题感兴趣的专栏:

public class Cell : INotifyPropertyChanged
{
    public string TestImageAspect
    {
        get { return testImageAspect; }
        set
        {
            testImageAspect = value;
            Console.WriteLine("OnPropertyChanged => testImageAspect");
            this.OnPropertyChanged("OperationResult");
        }
    }
    private string testImageAspect;
}

ImageList 已准备好所需图片。在 ObjectListView 中,我将适当列的 ImageAspectName 设置为 属性 名称:

然后在按钮上单击我 运行 下面的代码来更改

  Cell c = ...;
  c.TestImageAspect = "success"; // the name exist in ImageList

在上面的代码之后,我看到 OnPropertyChanged 已被调用,但是 UI 没有更新,除非我将鼠标悬停到它必须更改的行,然后我会看到新图标。我不是在寻找肮脏的解决方法,因为我知道的很少,而是想了解 ObjectListView 是否必须更新 UI 本身。如果是,我做错了什么?

您能否 post 绑定的 XAML - 这可能有助于调试它。此外,您的 属性 被称为 TestImageAspect 但您将 "OperationResult" 传递给 OnPropertyChanged,这有点令人困惑。我不确定 OnPropertyChanged 是否也能工作。更通常的方法是:-

public class Cell : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public string TestImageAspect
    {
        get { return testImageAspect; }
        set
        {
            testImageAspect = value;
            if (PropertyChanged != null)
            {
               PropertyChanged(this, new PropertyChangedEventArgs("TestImageAspect"));
            }

        }
    }
    private string testImageAspect;
}

必须设置ObjectListView 属性 UseNotifyPropertyChanged true.

From the official documentation

If you set UseNotifyPropertyChanged, then ObjectListView will listen for changes on your model classes, and automatically update the rows when properties on the model classes changed. Obviously, your model objects have to implement INotifyPropertyChanged.