小编yom*_*omi的帖子

如何为bool []中的值实现INotifyPropertyChanged功能?

我有一个大小为4的bool数组,我想将每个单元格绑定到不同的控件.此bool数组表示4个状态(false =失败,true =成功).这个bool数组是一个类:

class foo : INotifyPropertyChanged {
...
private bool[] _Statuses;
public bool[] Statuses
{
    get {return Statuses;}
    set {
            Statuses = value;
            OnPropertyChanged("Statuses");
        }
}
Run Code Online (Sandbox Code Playgroud)

在XAML中有4个控件,每个控件绑定到数组的一个单元:

... Text="{Binding Path=Statuses[0]}" ...
... Text="{Binding Path=Statuses[1]}" ...
... Text="{Binding Path=Statuses[2]}" ...
... Text="{Binding Path=Statuses[3]}" ...
Run Code Online (Sandbox Code Playgroud)

问题是只有当我更改数组本身时才会引发notify事件,而当我在数组中更改一个值时不会引发通知事件,即下一个代码行引发事件:

Statuses = new bool[4];
Run Code Online (Sandbox Code Playgroud)

但下一行不会引发事件:

Statuses [0] = true;
Run Code Online (Sandbox Code Playgroud)

每次更换一个单元格时,如何引发事件?

wpf binding inotifypropertychanged

10
推荐指数
2
解决办法
3154
查看次数

标签 统计

binding ×1

inotifypropertychanged ×1

wpf ×1