コード例 #1
0
 /// <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;
         }
     };
 }