public static void TreeItemExpand(TreeItem treeitem) { try { treeitem.EnsureVisible(); treeitem.Expand(); } catch (Exception ex) { throw new Exception("TreeItem Expand failed : " + ex.Message); } }
/// <summary> /// Expand a specified menu-entry within the tree. /// </summary> /// <param name="treeitem">TreeItem to expand</param> /// <returns> /// <br>True: If call worked fine</br> /// <br>False: If an error occurred</br> /// </returns> public bool ExpandMenu(TreeItem treeitem) { try { if (!treeitem.Expanded) { treeitem.Expand(); } return(true); } catch (Exception exception) { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message); return(false); } }
/// <summary> /// Search and returns a tree item behind a specified path. /// </summary> /// <param name="strPath">Item (menu / parameter) to search for.</param> /// <returns> /// <br>TreeItem: If call worked fine</br> /// <br>Null: If an error occurred</br> /// </returns> private TreeItem GetTreeItemByPath(string strPath) { string[] seperator = { "//" }; string[] pathParts = strPath.Split(seperator, StringSplitOptions.None); int counter = 0; int lastFoundTreeItemChildIndex = -1; TreeItem lastFoundTreeItem = null; TreeItem treeItem = null; try { for (counter = 0; counter < pathParts.Length; counter++) { // Get treeitem if it is visible at current GUI treeItem = NavigationElements.GetTreeItem(pathParts[counter], lastFoundTreeItemChildIndex); if (counter == pathParts.Length - 2 && treeItem != null) { treeItem.Click(); Parameter parameter = new Application().GetParameterStateFast(pathParts[pathParts.Length - 1]); if (parameter.ParameterState != ParameterState.NotRecognized) { return(treeItem); } } if (treeItem == null) { // If scrollbar active and not null if (NavigationElements.VerticalScrollbar != null && NavigationElements.VerticalScrollbar.Enabled) { if (NavigationElements.PageUpButton.ScreenRectangle.Size.Height == 0) { // If scrollbar is on top // Scroll down treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageDownButton, pathParts[counter], lastFoundTreeItemChildIndex); } else if (NavigationElements.PageDownButton.ScreenRectangle.Size.Height == 0) { // If scrollbar is on bottom // Scroll up treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageUpButton, pathParts[counter], lastFoundTreeItemChildIndex); } else if (NavigationElements.PageUpButton.ScreenRectangle.Size.Height <= NavigationElements.PageDownButton.ScreenRectangle.Size.Height) { // If scrollbar is nearly on top // Scroll down first treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageDownButton, pathParts[counter], lastFoundTreeItemChildIndex); // Scroll up as next if treeItem noch found if (treeItem == null) { treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageUpButton, pathParts[counter], lastFoundTreeItemChildIndex); } } else if (NavigationElements.PageUpButton.ScreenRectangle.Size.Height > NavigationElements.PageDownButton.ScreenRectangle.Size.Height) { // If scrollbar is nearly on bottom // Scroll down first treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageDownButton, pathParts[counter], lastFoundTreeItemChildIndex); // Scroll up as next if treeItem noch found if (treeItem == null) { treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageUpButton, pathParts[counter], lastFoundTreeItemChildIndex); } } else { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Impossible path at if-then-else structure."); } } else { // if Scrollbar not active search for treeitem with index greater than last found Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Treeitem " + "[" + pathParts[counter] + "]" + " not found"); } } if (treeItem != null) { treeItem.MoveTo(); lastFoundTreeItemChildIndex = treeItem.Element.ChildIndex; lastFoundTreeItem = treeItem; } if (counter >= (pathParts.Length - 1)) { continue; } if (treeItem != null) { treeItem.Expand(); } } return(lastFoundTreeItem); } catch (Exception exception) { Log.Error("Navigation.GetTreeItemByPath@" + pathParts[counter], exception.Message); return(null); } }