Ejemplo n.º 1
0
        public NestedMenu()
        {
            DataContext = this;
            Nodes = new ObservableCollection<AbstractNode>();
            Path = new ObservableCollection<Node>();

            InitializeComponent();

            var r1 = new Node() { Name = "Root 1" };
            r1.Children.Add(new Leaf() { Name = "Leaf", Parent=r1 });
            r1.Children.Add(new Node() { Name = "Node 1", Parent=r1 });

            var r2 = new Node() { Name = "Root 2" };
            r2.Children.Add(new Leaf() { Name = "Leaf 2", Parent=r2 });
            r2.Children.Add(new Node() { Name = "Node 3", Parent=r2 });

            Nodes.Add(r1);
            Nodes.Add(r2);

            var megaroot = new Node() { Name = "Home" };
            megaroot.Children.Add(r1);
            megaroot.Children.Add(r2);
            r1.Parent = megaroot;
            r2.Parent = megaroot;

            SelectedNode = megaroot;
            Path.Add(megaroot);
        }
Ejemplo n.º 2
0
        public void Back()
        {
            if (SelectedNode == null || SelectedNode.Parent == null)
                return;

            Path.Remove(SelectedNode);
            SelectedNode = SelectedNode.Parent as Node;
        }
Ejemplo n.º 3
0
        public void Navigate(AbstractNode destinationNode)
        {
            Node node = destinationNode as Node;
            Leaf leaf = destinationNode as Leaf;

            if (node != null)
            {
                Path.Add(destinationNode);
                SelectedNode = node;
            }
            if (leaf != null)
            {
                // NavigationService invoke
            }
        }
Ejemplo n.º 4
0
        public DynamicNestedMenu2()
        {
            Nodes = new ObservableCollection<AbstractNode>();
            Path = new ObservableCollection<AbstractNode>();

            //SelectedNode =
            var r1 = new Node() { Name = "Root 1" };
            r1.Children.Add(new Leaf() { Name = "Leaf" });
            r1.Children.Add(new Node() { Name = "Node 1" });

            var r2 = new Node() { Name = "Root 2" };
            r2.Children.Add(new Leaf() { Name = "Leaf 2" });
            r2.Children.Add(new Node() { Name = "Node 3" });

            Nodes.Add(r1);
            Nodes.Add(r2);

            SelectedNode = new Node() { Name = "MegaRoot" };
            SelectedNode.Children.Add(r1);
            SelectedNode.Children.Add(r2);
        }
Ejemplo n.º 5
0
        private static void NodesChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var oldValue = e.OldValue as ObservableCollection<AbstractNode>;
            if(oldValue!=null)
                oldValue.CollectionChanged -= CollectionChanged;
            var newValue = e.NewValue as ObservableCollection<AbstractNode>;
            if(newValue!=null)
                newValue.CollectionChanged += CollectionChanged;

            var control = sender as NestedMenu;
            if (control != null && control.Path != null)
            {
                var root = new Node() { Name = "Home" };
                foreach (var node in newValue)
                    root.Children.Add(node);

                control.Path.Clear();
                control.SelectedNode = root;
                control.Path.Add(root);
            }
        }
Ejemplo n.º 6
0
 public bool IsAnchestor(Node anchestor, Node node)
 {
     var parent = node.Parent as Node;
     if (parent != null && parent == anchestor)
         return true;
     else
         if (node.Parent == null)
             return false;
         else
             return IsAnchestor(anchestor, parent);
 }
Ejemplo n.º 7
0
        public void Back(Node destinationNode)
        {
            foreach (var node in Path.ToList())
                if (IsAnchestor(destinationNode, node))
                    Path.Remove(node);

            SelectedNode = destinationNode;
        }