Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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中的“全选”复选框不会';不要更改列表框中的其他复选框_C#_Wpf_Listbox - Fatal编程技术网

C# 选中WPF中的“全选”复选框不会';不要更改列表框中的其他复选框

C# 选中WPF中的“全选”复选框不会';不要更改列表框中的其他复选框,c#,wpf,listbox,C#,Wpf,Listbox,我使用和实现了一个ListBox。我将我的29个对象的实际列表绑定到它,它工作得很好。 在XAML中: 代码: 我不知道该怎么办 提前感谢,Mo您的属性已检查实现可能如下所示 public class Datenpunkt : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void Notify(string propertyName)

我使用和实现了一个
ListBox
。我将我的29个对象的实际列表绑定到它,它工作得很好。 在XAML中:

代码:

我不知道该怎么办


提前感谢,Mo

您的属性已检查实现可能如下所示

public class Datenpunkt : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public void Notify(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private bool _isChecked;
    public bool IsChecked
    {
        get { return _isChecked; }
        set
        {
            _isChecked = value;
            Notify("IsChecked");
        }
    }
}

查看页面了解更多信息。

您是否为您的
Datenpunkt
类的
IsChecked
属性实现了
INotifyPropertyChanged
接口?@MightyBadaboom否。它应该是这样的吗?public static readonly dependencProperty isCheckedProperty=dependencProperty.Register(“IsChecked”、typeof(bool)、typeof(MainWindow)、new UIPropertyMetadata(null));如果要将属性绑定到xaml,并且希望在通过代码更改属性时更新ui,则必须实现
INotifyPropertyChanged
接口。不,那将是一个依赖属性。@MightyBadaboom。我现在就查
datenpunktList = new ObservableCollection<Datenpunkt>();
foreach (var d in WerkstattList.DistinctBy(p => p.lokNr))
{
    var newd = new Datenpunkt() { Baunr = d.lokNr };
    datenpunktList.Add(newd);
}

WBauNrList.ItemsSource = datenpunktList;
<CheckBox Name="selectAll" Click="selectAll_Click" >Secelct all</CheckBox>
private void selectAll_Click(object sender, RoutedEventArgs e)
{
    foreach (Datenpunkt item in WBauNrList.Items)
    {
        item.IsChecked = true ;
    }
}
public class Datenpunkt : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public void Notify(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private bool _isChecked;
    public bool IsChecked
    {
        get { return _isChecked; }
        set
        {
            _isChecked = value;
            Notify("IsChecked");
        }
    }
}