public CategoryViewModel(Category category) : base(category) { PatternViewModels = new ObservableViewModelCollection <PatternViewModel, Pattern>(Model.Patterns, p => new PatternViewModel(p)); if (PatternViewModels.Any()) { PatternViewModels.First().IsSelected = true; } }
public MainWindow() { InitializeComponent(); DataContext = this; categories = new ObservableCollection <Category>(); for (int c = 1; c < 6; c++) { var cc = new Category { Name = string.Format("Category {0}", c) }; categories.Add(cc); for (int p = 1; p < 6; p++) { var cp = new Pattern(string.Format("Pattern {0}-{1}", c, p), string.Format("*{0}*", p)); cc.Patterns.Add(cp); } } CategoryViewModels = new ObservableViewModelCollection <CategoryViewModel, Category>(categories, m => new CategoryViewModel(m)); CategoryViewModels.First().IsSelected = true; }