Ver Fonte

Tidied up docs and fixed several methods to be virtual

tznind há 4 anos atrás
pai
commit
62a997f4b3

+ 3 - 3
Terminal.Gui/Views/TreeView.cs

@@ -38,13 +38,13 @@ namespace Terminal.Gui {
 		/// Children of the current node
 		/// </summary>
 		/// <returns></returns>
-		public IList<ITreeNode> Children {get;set;} = new List<ITreeNode>();
+		public virtual IList<ITreeNode> Children {get;set;} = new List<ITreeNode>();
 		
 		/// <summary>
 		/// Text to display in tree node for current entry
 		/// </summary>
 		/// <value></value>
-		public string Text {get;set;}
+		public virtual string Text {get;set;}
 
 		/// <summary>
 		/// Optionally allows you to store some custom data/class here.
@@ -730,7 +730,7 @@ namespace Terminal.Gui {
 		/// Raises the <see cref="ObjectActivated"/> event
 		/// </summary>
 		/// <param name="e"></param>
-		protected void OnObjectActivated(ObjectActivatedEventArgs<T> e)
+		protected virtual void OnObjectActivated(ObjectActivatedEventArgs<T> e)
 		{
 			ObjectActivated?.Invoke(e);
 		}

+ 3 - 11
UICatalog/Scenarios/TreeUseCases.cs

@@ -45,28 +45,20 @@ namespace UICatalog.Scenarios {
         // Your data class
 		private class House : TreeNode {
 
-
             // Your properties
             public string Address {get;set;}
             public List<Room> Rooms {get;set;}
 
             // ITreeNode member:
+			public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
 
-			public IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
-			
-            public override string ToString ()
-			{
-				return Address;
-			}
+			public override string Text { get => Address; set => Address = value; }
 		}
 		private class Room : TreeNode{
             
             public string Name {get;set;}
 
-			public override string ToString ()
-			{
-				return Name;
-			}
+			public override string Text{get=>Name;set{Name=value;}}
         }
 
 		private void LoadRooms()

+ 6 - 17
docfx/articles/treeview.md

@@ -35,35 +35,24 @@ Having to create a bunch of TreeNode objects can be a pain especially if you alr
 ```csharp
 // Your data class
 private class House : TreeNode {
-
-
+		
     // Your properties
     public string Address {get;set;}
     public List<Room> Rooms {get;set;}
 
     // ITreeNode member:
+	public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
 
-    public IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
-    
-    public override string ToString ()
-    {
-        return Address;
-    }
+	public override string Text { get => Address; set => Address = value; }
 }
 
+
 // Your other data class
 private class Room : TreeNode{
-    
+           
     public string Name {get;set;}
 
-
-    // Rooms have no sub objects
-    public IList<ITreeNode> Children => new List<ITreeNode>();
-
-    public override string ToString ()
-    {
-        return Name;
-    }
+	public override string Text{get=>Name;set{Name=value;}}
 }
 ```