我有这样的课:
public class ResourceList : ObservableCollection<Resource>
{
public ResourceList() : base()
{
}
}
public class Resource
{
public Resource()
{
Name = "";
EMail = "";
Date = "";
Time = "";
SWList = new ObservableCollection<string>();
}
public string Name { get; set; }
public string EMail { get; set; }
public string Date { get; set; }
public string Time { get; set; }
public ObservableCollection<string> SWList { get; set; }
}
public class Licenses : ObservableCollection<Licenses>
{
public Licenses()
{
}
public string Name { get; set; }
public string License { get; set; }
}
以及以下两个命令,它们看起来几乎相同:
internal class ReadResourceFilesCommand : ICommand
{
public ReadResourceFilesCommand(ResourceViewModel viewModel)
{
_viewModel = viewModel;
}
private ResourceViewModel _viewModel;
#region ICommand Members
event EventHandler ICommand.CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
}
remove
{
CommandManager.RequerySuggested -= value;
}
}
bool ICommand.CanExecute(object parameter)
{
return _viewModel.CanUpdate;
}
void ICommand.Execute(object parameter)
{
_viewModel.ReadResourceFile(parameter.ToString());
}
#endregion
}
internal class ReadInventoryFilesCommand : ICommand
{
public ReadInventoryFilesCommand(ResourceViewModel viewModel)
{
_viewModel = viewModel;
}
private ResourceViewModel _viewModel;
#region ICommand Members
event EventHandler ICommand.CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
}
remove
{
CommandManager.RequerySuggested -= value;
}
}
bool ICommand.CanExecute(object parameter)
{
return _viewModel.CanUpdate;
}
void ICommand.Execute(object parameter)
{
_viewModel.ReadInventroyFiles(parameter.ToString());
}
#endregion
}
CanUpdate
和我的 viewModelResourceList
看起来像这样:
public bool CanUpdate
{
get
{
if (ResourceList == null)
{
return false;
}
return true;
}
}
public ResourceList ResourceList
{
get
{
return _ResourceList;
}
set
{
if (value == _ResourceList)
return;
_ResourceList = value;
// INotifyPropertyChanged Method for updating the binding
onPropertyChanged("ResourceList");
}
}
现在实际问题:当第一个命令被执行时,不管是哪个命令,GUI 中的listView都被填充,一切看起来都很好。但是当执行另一个命令时(实际上更新了同一个列表中的元素,所有元素的时间和日期属性都会更新)listView不会更新它的元素。
我知道我没有更改整个列表,我正在更新其中的一些元素,这可能就是它没有被更新的原因。但我真的不知道该怎么办?请解释我应该如何修改代码!