Exemplo n.º 1
0
        /// <summary>
        /// Handles a change to the Navigation change property.
        /// </summary>
        /// <param name="dependencyObject">The object that owns the property.</param>
        /// <param name="dependencyPropertyChangedEventArgs">A description of the changed property.</param>
        private static void OnSelectedValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // Extract the variables from the generic arguments.
            FolderNavBar  folderNavBar = dependencyObject as FolderNavBar;
            FolderNavNode newValue     = dependencyPropertyChangedEventArgs.NewValue as FolderNavNode;

            folderNavBar.breadcrumb.SelectedItem = newValue;
            folderNavBar.history.Remove(newValue);
            folderNavBar.history.Insert(0, newValue);
            if (folderNavBar.MaxHistoryCount != 0 && folderNavBar.history.Count > folderNavBar.MaxHistoryCount)
            {
                folderNavBar.history.RemoveAt(folderNavBar.history.Count - 1);
            }
        }
        /// <summary>
        ///  GetPath of the item
        /// </summary>
        /// <param name="rootItem"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static string GetPath(object rootItem, object item)
        {
            FolderNavNode rootNode   = rootItem as FolderNavNode;
            FolderNavNode targetNode = item as FolderNavNode;

            if (null == rootNode || null == targetNode)
            {
                return(string.Empty);
            }

            if (rootNode.Entity.EntityId == targetNode.Entity.EntityId)
            {
                return(rootNode.Entity.Name);
            }

            TreeTraverseHelper.Node <FolderNavNode> leafNode = rootNode.FindLeafNode(
                t => t.Entity.EntityId == targetNode.Entity.EntityId,
                (parent) => parent.Children
                );


            //Unwind the leaf node.
            if (leafNode != null)
            {
                List <FolderNavNode> listPath = new List <FolderNavNode>();
                TreeTraverseHelper.Node <FolderNavNode> currentNode = leafNode;
                do
                {
                    listPath.Add(currentNode.Item);
                    currentNode = currentNode.Parent;
                }while (currentNode != null);

                listPath.Reverse();

                StringBuilder path = new StringBuilder(rootNode.Entity.Name);
                foreach (var node in listPath)
                {
                    path.Append(Path.DirectorySeparatorChar + node.Entity.Name);
                }

                return(path.ToString());
            }

            return(String.Empty);
        }
        /// <summary>
        /// Gets the id for the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static string GetObjectName(object item)
        {
            if (item is FolderNavNode)
            {
                FolderNavNode FolderNavNode = item as FolderNavNode;
                return(FolderNavNode.Entity.Name);
            }
            else
            {
                EntityNode entity = item as EntityNode;
                if (null != entity)
                {
                    return(entity.Name);
                }
            }

            return(String.Empty);
        }
        /// <summary>
        /// Gets the trail for the specified item.
        /// </summary>
        /// <param name="rootItem">The root item.</param>
        /// <param name="path">The item.</param>
        /// <returns></returns>
        public static IList GetTrail(object rootItem, string path)
        {
            // Make sure the specified path is valid
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            // If the root item was not passed, then we cannot build a trail
            FolderNavNode rootNode = rootItem as FolderNavNode;

            if (null == rootNode)
            {
                return(null);
            }

            return(GetPathList(path, rootNode));
        }
        private static IList GetPathList(string path, FolderNavNode rootNode)
        {
            // Break the path up based on the available path separators
            string[] pathEntries = path.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
                                              StringSplitOptions.RemoveEmptyEntries);
            if (null == pathEntries || 0 == pathEntries.Length)
            {
                return(null);
            }

            List <object> trail = new List <object>();

            trail.Add(rootNode);

            IEnumerable <FolderNavNode> currentDepthCollection = rootNode;

            //Start from 1 since the rootnode is already added.
            for (int index = 1; index < pathEntries.Length; index++)
            {
                bool bEntryFound = false;
                foreach (var treeNode in currentDepthCollection)
                {
                    if (string.CompareOrdinal(treeNode.Entity.Name, pathEntries[index]) == 0)
                    {
                        trail.Add(treeNode);
                        bEntryFound            = true;
                        currentDepthCollection = treeNode.Children;
                        break;
                    }
                }

                if (false == bEntryFound)
                {
                    ReportPathError(path);
                    return(null);
                }
            }
            return(trail);
        }
Exemplo n.º 6
0
 private void OnSelectedItemChanged(object sender, ActiproSoftware.Windows.ObjectPropertyChangedRoutedEventArgs routedPropertyChangedEventArgs)
 {
     try
     {
         if (this.RootNode != null)
         {
             // Extract the selected node from the event arguments.
             FolderNavNode selectedNode = routedPropertyChangedEventArgs.NewValue as FolderNavNode;
             if (selectedNode != null)
             {
                 RoutedEventArgs newEventArgs = new RoutedEventArgs(FolderNavBar.NodeSelectionChangedEvent);
                 newEventArgs.Source = selectedNode;
                 RaiseEvent(newEventArgs);
             }
         }
     }
     catch (Exception ex)
     {
         System.Console.Error.WriteLine(ex.Message);
         throw;
     }
 }