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");
}
}
}