/// <summary> /// Initializes a new instance of the <see cref="TreeFragment" /> class. /// </summary> public TreeFragment() { InitializeComponent(); btnAddBranch.Command = new DelegateCommand(() => { if (SelectedItem == null) { return; } if (Root == null) { return; } var brc = Root.AddBranch(); CurrentNode = AddNode(null, brc); }); btnAddChild.Command = new DelegateCommand(() => { if (CurrentNode == null) { return; } if (SelectedItem == null) { return; } var chld = SelectedItem.AddChild(); AddNode(CurrentNode, chld); }); btnAddFolder.Command = new DelegateCommand(() => { if (CurrentNode == null) { return; } if (SelectedItem == null) { return; } var fld = SelectedItem.AddFolder(); AddNode(CurrentNode, fld); }); DataContextChanged += (s, e) => { if (e.NewValue is IComposedObject) { Root = e.NewValue as IComposedObject; } }; }
public MainVM() { var bobbyJoe = new Person("Bobby Joe", new[] { new Pet("Fluffy") }); var bob = new Person("Bob", new[] { bobbyJoe }); var littleJoe = new Person("Little Joe"); var joe = new Person("Joe", new[] { littleJoe }); Family = new ReactiveList <TreeItem> { bob, joe }; _addPerson = ReactiveCommand.Create(); _addPerson.Subscribe(_ => { if (SelectedItem == null) { return; } var p = new Person(NewName); SelectedItem.AddChild(p); p.IsSelected = true; p.ExpandPath(); }); _addPet = ReactiveCommand.Create(); _addPet.Subscribe(_ => { if (SelectedItem == null) { return; } var p = new Pet(PetName); SelectedItem.AddChild(p); p.IsSelected = true; p.ExpandPath(); }); _collapse = ReactiveCommand.Create(); _collapse.Subscribe(_ => { SelectedItem?.CollapsePath(); }); }