Отказались от моего подхода и пошли с одним на основе примера кода проекта:
Упрощение WPF TreeView с помощью шаблона ViewModel
public class CountryViewModel : TreeViewItemViewModel
{
readonly Country _country;
public CountryViewModel(Country country)
: base(null, true)
{
_country = country;
}
public string CountryName
{
get { return _country.CountryName; }
}
public IEnumerable<State> States { get; set; }
public IEnumerable<County> Counties { get; set; }
public IEnumerable<DRC_SQLITE_Mines.Mine> Mines { get; set; }
public IEnumerable<DRC_SQLITE_locations.Location> Locations { get; set; }
protected override void LoadChildren()
{...}
}
public class StateViewModel : TreeViewItemViewModel
{
readonly State _state;
public StateViewModel(State state, CountryViewModel parentCountry)
: base(parentCountry, true)
{
_state = state;
}
public string StateName
{
get { return _state.StateName; }
}
public IEnumerable<County> Counties { get; set; }
public IEnumerable<DRC_SQLITE_Mines.Mine> Mines { get; set; }
public IEnumerable<DRC_SQLITE_locations.Location> Locations { get; set; }
protected override void LoadChildren()
{...}
}
открытый класс CountyViewModel: TreeViewItemViewModel
{
только для чтения округа _county;
public CountyViewModel(County county, StateViewModel parentState)
: base(parentState, true)
{
_county = county;
}
public string CountyName
{
get { return _county.CountyName; }
}
public IEnumerable<DRC_SQLITE_Mines.Mine> Mines { get; set; }
public IEnumerable<DRC_SQLITE_locations.Location> Locations { get; set; }
protected override void LoadChildren()
{...}
}
public class MineViewModel : TreeViewItemViewModel
{
public MineViewModel(DRC_SQLITE_Mines.Mine mine, CountyViewModel parentCounty)
: base(parentCounty, false)
{
Mine = mine;
}
public MineViewModel(DRC_SQLITE_Mines.Mine mine, StateViewModel parentState)
: base(parentState, false)
{
Mine = mine;
}
public MineViewModel(DRC_SQLITE_Mines.Mine mine, CountryViewModel parentCountry)
: base(parentCountry, false)
{
Mine = mine;
}
public DRC_SQLITE_Mines.Mine Mine { get; }
RelayCommand _viewDataCommand;
public ICommand ViewDataCommand
{...}
}