WPF DataGrid DataGridCheckBoxColumn vs2010 c#.net
我在vs2010工作。 我已经创建了一个数据网格,它绑定到 可观察收集清单 类_CMD如下所示:WPF DataGrid DataGridCheckBoxColumn vs2010 c#.net,c#,.net,wpf,visual-studio-2010,datagrid,C#,.net,Wpf,Visual Studio 2010,Datagrid,我在vs2010工作。 我已经创建了一个数据网格,它绑定到 可观察收集清单 类_CMD如下所示: public class Class_RetrieveCommand { public string CMD { get; set; } public bool C_R_CMD { get; set; } public bool S_CMD { get; set; } public bool C_S_CMD { get; set; } } 我有4个委托,我将其传递
public class Class_RetrieveCommand
{
public string CMD { get; set; }
public bool C_R_CMD { get; set; }
public bool S_CMD { get; set; }
public bool C_S_CMD { get; set; }
}
我有4个委托,我将其传递给另一个窗口,该窗口需要在运行时更新列表。在运行期间,我可以看到网格的字符串列一直在更新,但DataGridCheckBoxColumns从未更新
数据网格-
<DataGrid Background="Transparent" x:Name="DataGrid_CMD" Width="450" MaxHeight="450" Height="Auto" ItemsSource="{Binding}" AutoGenerateColumns="True">
我不明白为什么bool列没有更新。。。。
有人能帮忙吗?
谢谢。您的类\u RetrieveCommand需要实现INotifyPropertyChanged接口。否则,绑定到类实例的单个行不知道基础属性已更改。如果将其更改为以下内容,您应该可以看到网格中反映的更改:
public class Class_RetrieveCommand : INotifyPropertyChanged
{
private bool _cRCmd;
private bool _cSCmd;
private string _cmd;
private bool _sCmd;
public string CMD
{
get { return _cmd; }
set
{
_cmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("CMD"));
}
}
public bool C_R_CMD
{
get { return _cRCmd; }
set
{
_cRCmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("C_R_CMD"));
}
}
public bool S_CMD
{
get { return _sCmd; }
set
{
_sCmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("S_CMD"));
}
}
public bool C_S_CMD
{
get { return _cSCmd; }
set
{
_cSCmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("C_S_CMD"));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
public void InvokePropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
}
您的类\u RetrieveCommand需要实现INotifyPropertyChanged接口。否则,绑定到类实例的单个行不知道基础属性已更改。如果将其更改为以下内容,您应该可以看到网格中反映的更改:
public class Class_RetrieveCommand : INotifyPropertyChanged
{
private bool _cRCmd;
private bool _cSCmd;
private string _cmd;
private bool _sCmd;
public string CMD
{
get { return _cmd; }
set
{
_cmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("CMD"));
}
}
public bool C_R_CMD
{
get { return _cRCmd; }
set
{
_cRCmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("C_R_CMD"));
}
}
public bool S_CMD
{
get { return _sCmd; }
set
{
_sCmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("S_CMD"));
}
}
public bool C_S_CMD
{
get { return _cSCmd; }
set
{
_cSCmd = value;
InvokePropertyChanged(new PropertyChangedEventArgs("C_S_CMD"));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
public void InvokePropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
}
您应该在类\u RetrieveCommand
中实现如下内容:
public class Class_RetrieveCommand : INotifyPropertyChanged
{
private string _CMD;
public string CMD
{
get { return _CMD; }
set { _CMD = value; OnPropertyChanged("CMD"); }
}
... similar for the other properties
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
不幸的是,您不能再使用自动属性(除非您使用代理生成器)。您应该在类\u RetrieveCommand
中实现如下:
public class Class_RetrieveCommand : INotifyPropertyChanged
{
private string _CMD;
public string CMD
{
get { return _CMD; }
set { _CMD = value; OnPropertyChanged("CMD"); }
}
... similar for the other properties
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
不幸的是,你不能再使用自动属性了(除非你求助于ProxyGenerator)