Remove() public method

public Remove ( TreeNode node ) : void
node TreeNode
return void
示例#1
0
        public void Remove()
        {
            Tree tree = Tree;

            if (tree != null)
            {
                tree.Remove(this);
            }
            else if (_parent != null)
            {
                _parent.Remove(this);
            }
        }
示例#2
0
        protected override void InitializeCore()
        {
            ShowDebug = true;

            _stage = new Stage(Context.GraphicsDevice);
            Context.Input.Processor = _stage;

            Skin skin = new Skin(Context.GraphicsDevice, "Data/uiskin.json");

            Table table = new Table();
            table.SetFillParent(true);
            _stage.AddActor(table);

            Tree tree = new Tree(skin);

            TreeNode node1 = new TreeNode(new TextButton("moo1", skin));
            TreeNode node2 = new TreeNode(new TextButton("moo2", skin));
            TreeNode node3 = new TreeNode(new TextButton("moo3", skin));
            TreeNode node4 = new TreeNode(new TextButton("moo4", skin));
            TreeNode node5 = new TreeNode(new TextButton("moo5", skin));

            tree.Add(node1);
            tree.Add(node2);
            node2.Add(node3);
            node3.Add(node4);
            tree.Add(node5);

            Label label = new Label("", skin, "default");

            tree.SelectionChanged += (sender, e) => {
                if (e.AddedItems.Count == 0)
                    return;

                StringBuilder txt = new StringBuilder();
                foreach (TreeNode node in e.AddedItems) {
                    TextButton button = node.Actor as TextButton;
                    txt.Append(button.Text + ", ");
                }

                label.Text = txt.ToString();
                label.Invalidate();
            };

            (node5.Actor as Button).Clicked += (sender, e) => {
                tree.Remove(node4);
            };

            //node5.Actor.AddListener(new DispatchClickListener() {
            //    OnClicked = (ev, x, y) => { tree.Remove(node4); }
            //});

            table.Add(tree).Configure.Fill().Expand();
            table.Row();
            table.Add(label).Configure.Fill().Expand();

            //Debugger.Launch();
        }