MVVM+MEF:父视图模型使用MEF填充子视图模型
我以前问过这个问题,但它是一般形式的,所以我无法得到答案,所以在这里我将询问具体问题: 根据以下代码,我希望使用MEF重新编写此代码,而不是使用new operator,但我面临以下问题,需要解答: 1-构造函数中的CountryViewModel如何创建具有参数构造函数的子RegionViewModel集合,并通过模型对象填充它?我尝试使用GetExportedValues,但没有成功,因为我无法将参数传递给构造函数,也无法使用linq查询填充RegionViewModel,如代码所示 2-RegionViewModel如何在LoadChildren方法中加载StateViewModel的子视图模型集合 使用foreach块但也使用MEF不是新操作符?我还尝试使用GetExportedValues,但无法将参数传递给子视图模型MVVM+MEF:父视图模型使用MEF填充子视图模型,mvvm,mef,Mvvm,Mef,我以前问过这个问题,但它是一般形式的,所以我无法得到答案,所以在这里我将询问具体问题: 根据以下代码,我希望使用MEF重新编写此代码,而不是使用new operator,但我面临以下问题,需要解答: 1-构造函数中的CountryViewModel如何创建具有参数构造函数的子RegionViewModel集合,并通过模型对象填充它?我尝试使用GetExportedValues,但没有成功,因为我无法将参数传递给构造函数,也无法使用linq查询填充RegionViewModel,如代码所示 2-R
public class CountryViewModel
{
readonly ReadOnlyCollection<RegionViewModel> _regions;
public ReadOnlyCollection<RegionViewModel> Regions
{
get { return _regions; }
}
//---------------------------------------------------------
public CountryViewModel(Region[] regions)
{
_regions = new ReadOnlyCollection<RegionViewModel>(
(from region in regions
select new RegionViewModel(region))
.ToList());
}
}
public class RegionViewModel : TreeViewItemViewModel
{
readonly Region _region;
public RegionViewModel(Region region)
: base(null, true)
{
_region = region;
}
public string RegionName
{
get { return _region.RegionName; }
}
protected override void LoadChildren()
{
foreach (State state in Database.GetStates(_region))
base.Children.Add(new StateViewModel(state, this));
}
}