Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# wpf Datagrid复选框NotifyOnTargetUpdated不起作用_C#_Wpf_Checkbox_Datagrid_Inotifypropertychanged - Fatal编程技术网

C# wpf Datagrid复选框NotifyOnTargetUpdated不起作用

C# wpf Datagrid复选框NotifyOnTargetUpdated不起作用,c#,wpf,checkbox,datagrid,inotifypropertychanged,C#,Wpf,Checkbox,Datagrid,Inotifypropertychanged,我的班级: public class BarCode : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) PropertyChang

我的班级:

public class BarCode : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

    public string code { get; set; }
    public string name { get; set; }
    public Visibility special1 { get; set; }
    public Visibility special2 { get; set; }
    private bool _x1, _x2;
    public bool x1
    {
        get
        {
            return _x1;
        }
        set
        {
            if (value && _x2)
                _x2 = false;
            _x1 = value;
            OnPropertyChanged("X1");
        }
    }
    public bool x2
    {
        get
        {
            return _x2;
        }
        set
        {
            if (value && _x1)
                _x1 = false;
            _x2 = value;
            OnPropertyChanged("X2");
        }
    }
}
XAML:


}尝试使用双向模式:

<CheckBox IsChecked="{Binding Path=.x1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}"/>


如果您只想让一个复选框影响另一个复选框的状态,那么elementbinding也会很有帮助。

我认为您过度考虑了绑定表达式

你有这个

<CheckBox IsChecked="{Binding Path=.x2, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}"/>

当你需要它的时候

<CheckBox IsChecked="{Binding Path=x2, Mode=TwoWay}"/>


您的属性是
x1
x2
,但您为
x1
x2
(大写X)引发事件,并且属性名称区分大小写。同样,当您在x1 setter中更改x2时,也要执行
x2=false或事件的
x2
以及谢谢dkozl,当我将设置器x2中的分配x1更改为x1时,它会工作。
<CheckBox IsChecked="{Binding Path=.x2, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}"/>
<CheckBox IsChecked="{Binding Path=x2, Mode=TwoWay}"/>