У меня есть приложение WPF с сеткой данных, для которой ItemsSource является BindingList. Когда я делаю изменения в объектах в BindingList, сетка данных не обновляется. Как я могу убедиться, что сетка данных обновляется, когда я изменяю объект в BindingList?
Вот XAML:
<DataGrid CanUserAddRows="False" AutoGenerateColumns="False" HorizontalAlignment="Stretch" Name="dgLocalPlugins" VerticalAlignment="Stretch" SelectionMode="Single" AlternatingRowBackground="#CDEBEBEB" Margin="5,85,5,143" Width="Auto" SelectionChanged="dgLocalPlugins_SelectionChanged">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Enabled" Binding="{Binding Path=Enabled}" Width="55" >
<DataGridCheckBoxColumn.CellStyle>
<Style>
<EventSetter Event="CheckBox.Checked" Handler="OnChecked"/>
<EventSetter Event="CheckBox.Unchecked" Handler="OnUnchecked"/>
</Style>
</DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>
<DataGridTextColumn Header="Plugin" Binding="{Binding Path=Type}" IsReadOnly="True" Width="*" />
<DataGridTextColumn Header="Status" Binding="{Binding Path=Status}" IsReadOnly="True" Width="*" />
</DataGrid.Columns>
</DataGrid>
Вот соответствующий код, где я заполняю BindingList:
private BindingList<PluginDescription> pluginList = new BindingList<PluginDescription>();
foreach (string path in osapdFiles)
{
if (!string.IsNullOrEmpty(path))
{
PluginDescription desc = PluginHelper.Deserialize(path);
pluginList.Add(desc);
}
}
dgLocalPlugins.ItemsSource = pluginList;
Вот класс PluginDescription:
public class PluginDescription : INotifyPropertyChanged
{
private string _pluginName;
public string Name
{
set
{
if (value != this._pluginName)
{
this._pluginName = value;
NotifyPropertyChanged("Name");
}
}
get { return _pluginName; }
}
private string _pluginType;
public string Type
{
set
{
if (value != this._pluginType)
{
this._pluginType = value;
NotifyPropertyChanged("Type");
}
}
get { return _pluginType; }
}
private string _pluginVersion;
public string Version
{
set
{
if (value != this._pluginVersion)
{
this._pluginVersion = value;
NotifyPropertyChanged("Version");
}
}
get { return _pluginVersion; }
}
private string _pluginAuthor;
public string Author
{
set
{
if (value != this._pluginAuthor)
{
this._pluginAuthor = value;
NotifyPropertyChanged("Author");
}
}
get { return _pluginAuthor; }
}
private string _wikiUrl;
public string WikiUrl
{
set
{
if (value != this._wikiUrl)
{
this._wikiUrl = value;
NotifyPropertyChanged("Wiki");
}
}
get { return _wikiUrl; }
}
private string _description;
public string Description
{
set
{
if (value != this._description)
{
this._description = value;
NotifyPropertyChanged("Description");
}
}
get { return _description; }
}
private string _status;
public string Status
{
set
{
if (value != this._status)
{
this._status = value;
NotifyPropertyChanged("Statua");
}
}
get { return _status; }
}
private bool _enabled;
public bool Enabled
{
set
{
if (value != this._enabled)
{
this._enabled = value;
NotifyPropertyChanged("Enabled");
}
}
get { return _enabled; }
}
private string _upgrade;
public string Upgrade
{
set
{
if (value != this._upgrade)
{
this._upgrade = value;
NotifyPropertyChanged("Upgrade");
}
}
get { return _upgrade; }
}
private string _path;
public string Path
{
set
{
if (value != this._path)
{
this._path = value;
NotifyPropertyChanged("Path");
}
}
get { return _path; }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
Теперь, когда я изменяю свойство одного из объектов PluginDescription, DataGrid не обновляется. Я думал, что реализация интерфейса INotifyPropertyChange в классе PluginDescription будет всем, что мне нужно. Мне нужно сделать что-то еще?