private ViewModelPlaceholder CreateTemplateNode(string label, string imagePath, Func <List <SiteExplorerNodeViewModel> > getTemplates) { var templateRoot = new ViewModelPlaceholder(label, imagePath); var model = templatesNode.ItemsSource as ObservableCollection <ViewModelPlaceholder>; if (model == null) { model = new ObservableCollection <ViewModelPlaceholder>(); templatesNode.ItemsSource = model; } model.Add(templateRoot); templateRoot.Children.Add(new ViewModelPlaceholder("Loading...")); templateRoot.LazyLoadChildren += new HierarchicalViewModelAction((parent) => { using (new OverrideCursor(Cursors.Wait)) { parent.Children.Clear(); foreach (SiteExplorerNodeViewModel child in getTemplates()) { parent.Children.Add(child); } } }); return(templateRoot); }
private void LoadExplorerModel() { var service = new MaterialService(User); // Region explorer... var list = service.GetTopLevelExplorerItems(); RegionsModel = BuildExplorerModel(list, false); regionsNode.ItemsSource = RegionsModel; regionsNode.IsExpanded = true; // Unplaced sites (Sites with no region)... list = service.GetTopLevelExplorerItems(SiteExplorerNodeType.Unplaced); UnplacedModel = BuildExplorerModel(list, false); unplacedNode.ItemsSource = UnplacedModel; // Templates... templatesNode.ItemsSource = null; _siteTemplatesRoot = CreateTemplateNode("Site Templates", @"images\Site.png", () => { var templates = service.GetSiteTemplates(); return(templates.ConvertAll((m) => { return new SiteExplorerNodeViewModel(m); })); }); _siteVisitTemplatesRoot = CreateTemplateNode("Site Visit Templates", @"images\SiteVisit.png", () => { var templates = service.GetSiteVisitTemplates(); return(templates.ConvertAll((m) => { return new SiteExplorerNodeViewModel(m); })); }); _materialTemplatesRoot = CreateTemplateNode("Material Templates", @"images\Material.png", () => { var templates = service.GetMaterialTemplates(); return(templates.ConvertAll((m) => { return new SiteExplorerNodeViewModel(m); })); }); }
private void LoadExplorerModel() { var service = new MaterialService(User); // Region explorer... var list = service.GetTopLevelExplorerItems(); RegionsModel = BuildExplorerModel(list, false); regionsNode.ItemsSource = RegionsModel; regionsNode.IsExpanded = true; // Unplaced sites (Sites with no region)... list = service.GetTopLevelExplorerItems(SiteExplorerNodeType.Unplaced); UnplacedModel = BuildExplorerModel(list, false); unplacedNode.ItemsSource = UnplacedModel; // Templates... templatesNode.ItemsSource = null; _siteTemplatesRoot = CreateTemplateNode("Site Templates", @"images\Site.png", () => { var templates = service.GetSiteTemplates(); return templates.ConvertAll((m) => { return new SiteExplorerNodeViewModel(m); }); }); _siteVisitTemplatesRoot = CreateTemplateNode("Site Visit Templates", @"images\SiteVisit.png", () => { var templates = service.GetSiteVisitTemplates(); return templates.ConvertAll((m) => { return new SiteExplorerNodeViewModel(m); }); }); _materialTemplatesRoot = CreateTemplateNode("Material Templates", @"images\Material.png", () => { var templates = service.GetMaterialTemplates(); return templates.ConvertAll((m) => { return new SiteExplorerNodeViewModel(m); }); }); }
private ViewModelPlaceholder CreateTemplateNode(string label, string imagePath, Func<List<SiteExplorerNodeViewModel>> getTemplates) { var templateRoot = new ViewModelPlaceholder(label, imagePath); var model = templatesNode.ItemsSource as ObservableCollection<ViewModelPlaceholder>; if (model == null) { model = new ObservableCollection<ViewModelPlaceholder>(); templatesNode.ItemsSource = model; } model.Add(templateRoot); templateRoot.Children.Add(new ViewModelPlaceholder("Loading...")); templateRoot.LazyLoadChildren += new HierarchicalViewModelAction((parent) => { using (new OverrideCursor(Cursors.Wait)) { parent.Children.Clear(); foreach (SiteExplorerNodeViewModel child in getTemplates()) { parent.Children.Add(child); } } }); return templateRoot; }