我的模型如下。
public class FItem
{
public FItem()
{
FSubsystems = new BindingList<FSubsystem>();
}
public int RecordId { get; set; }
public string ItemName { get; set; }
public BindingList<FSubsystem> FSubsystems { get; set; }
}
public class FSubsystem
{
public int SubSystemID { get; set; }
public string ItemName { get; set; }
public int YearID { get; set; }
}
代码 :
FItems = new ObservableCollection<MarketRecord.FItem>();
FItems.CollectionChanged += OnUiCollectionChanged;
private void OnUiCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var addedItem = e.NewItems[0] as MarketRecord.FItem;
if (addedItem != null)
{
addedItem.PropertyChanged += OnColumnModified;
if (addedItem.RecordId == 0)
modifedItems.Add(addedItem);
addedItem.FSubsystems.ListChanged += OnColumnModified;
}
}
}
private void OnColumnModified(object sender, EventArgs e)
{
if (sender.GetType().Name == "FItem")
{
MarketRecord.FItem modifiedItem = (sender as MarketRecord.FItem);
if (!modifedItems.Contains(modifiedItem))
modifedItems.Add(modifiedItem);
}
else
{
// add parent of the binding list (i.e fitem object ) add it to modifedItems
// Find parent here
}
}
正如我的代码告诉我需要在 OnColumnModified 的 else 子句中找到绑定列表的父项。我怎样才能做到这一点 ?