/// <summary> /// Adds a tree item to the children of this tree item /// <para>Use this method to handle select event in a proper way</para> /// </summary> /// <param name="child">child tree item to be added. Selected event handler will be automatically set</param> public void AddChild(BaseTreeItemVm child) { //add the event handler to the new item child.Selected += c => { if (Selected != null) Selected(c); }; Children.Add(child); }
/// <summary> /// Selects the given <see cref="BaseTreeItemVm"/> and changes the Content to show the skills about that <see cref="BaseTreeItemVm"/> /// </summary> /// <remarks> /// This method will be called from the Selected event in each <see cref="BaseTreeItemVm"/> /// <para>This method is using a timer to load content with a delay</para> /// </remarks> /// <param name="node">The node which skills will be shown</param> public void SelectNode(BaseTreeItemVm node) { //exit if page is in Loading state if (IsLoading) return; IsLoading = true; //load the content with a delay if (_loadingTimer != null) _loadingTimer.Dispose(); _loadingTimer = new Timer( o => { Dispatcher.Invoke(() => { //Reset the content to match the selected node Content = new SkillCenterContentVm(node); //prepare this page's Message to listen to errors of the Content Content.ErrorOccured += msg => Message.AddEmbeddedException(msg); IsLoading = false; }); } , null, _loadingTimerDelay, System.Threading.Timeout.Infinite); }
/// <summary> /// Instantiates an initializes this Vm with the given <see cref="BaseTreeItemVm"/> node /// </summary> /// <param name="node">A tree item that initializes the mode and data of this Vm</param> public SkillCenterContentVm(BaseTreeItemVm node) { SelectedItem = node; if (node is GeneralVm) { _targetMode = TargetMode.General; } else if (node is ProductGroupVm) { _targetMode = TargetMode.ProductGroup; } else if (node is ProductVm) { _targetMode = TargetMode.Product; } else if (node is ProductReworkVm) { _targetMode = TargetMode.ProductRework; } initializeData(); }