发布后几分钟,我意识到一切都已经正确设置,我只是在包含(/相关)表属性的 xaml 绑定上有一个错字:
我的视图模型相关代码如下:
public ObservableCollection<MasterPartNumber> AssyPns
{
get
{
var enumerable = this._context.MasterPartNumbers.Include("MasterPartsLists").Where(t => t.MasterPartsLists.Any(x => x.isAssy == true));
return this._assyPns = new ObservableCollection<MasterPartNumber>(enumerable);
}
set
{
this._assyPns = value;
RaisePropertyChanged("AssyPns");
}
}
public MasterPartNumber SelectedTopLevelAssyPN //<-- this is the selected Parent item i am getting my DataGrid's ObservableCollection from
{
get { return this._selectedTopLevelAssyPN; }
set
{
this._selectedTopLevelAssyPN = value;
RaisePropertyChanged("SelectedTopLevelAssyPN");
RaisePropertyChanged("SelectedAssyBOMLineItems");
}
}
public ObservableCollection<MasterPartsList> SelectedAssyBOMLineItems //<-- this is my itemsSource
{
get
{
if (this._selectedTopLevelAssyPN != null)
{
var children = _context.MasterPartsLists.Where(lineItem => lineItem.parentAssyPN != null)
.Where(lineItem => lineItem.parentAssyPN == this._selectedTopLevelAssyPN.pn);
return this._selectedAssyBOMLineItems = new ObservableCollection<MasterPartsList>(children);
}
return this._selectedAssyBOMLineItems;
}
set
{
this._selectedAssyBOMLineItems = value;
RaisePropertyChanged("SelectedAssyBOMLineItems");
}
}
我将 dataGrid TextColumn 绑定到的路径只是
{Binding MasterPartNumber.pnDesc}
谢谢两位这么及时的回复。